Skip to content

Commit

Permalink
Close web socket in case of failure
Browse files Browse the repository at this point in the history
  • Loading branch information
PattaFeuFeu committed Dec 17, 2023
1 parent 664ba8a commit 47eef95
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bigbone/src/main/kotlin/social/bigbone/MastodonClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,17 @@ private constructor(
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
super.onFailure(webSocket, t, response)
callback.onEvent(Failure(t))

/*
onFailure represents a terminal event and no further events would be received by this web socket,
so we close it.
1002 indicates that an endpoint is terminating the connection due to a protocol error.
see: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4
*/
webSocket.close(
code = 1002,
reason = null
)
}

override fun onMessage(webSocket: WebSocket, text: String) {
Expand Down

0 comments on commit 47eef95

Please sign in to comment.