websocket: Relay disconnect errors to subscribers (#1347)

* WS: Relay disconnect errors to subscribers

Subscribers probably care when the WS got disconncted.
Tell them and expose a method to test the error for matching

* Fix linter error
This commit is contained in:
Gareth Kirwan
2023-09-14 01:14:04 +01:00
committed by GitHub
parent bcabf44b8c
commit c8ec22fe92
3 changed files with 14 additions and 13 deletions

View File

@@ -391,16 +391,15 @@ func (w *Websocket) connectionMonitor() error {
}
select {
case err := <-w.ReadMessageErrors:
if isDisconnectionError(err) {
if IsDisconnectionError(err) {
w.setInit(false)
log.Warnf(log.WebsocketMgr,
"%v websocket has been disconnected. Reason: %v",
w.exchangeName, err)
w.setConnectedStatus(false)
} else {
// pass off non disconnect errors to datahandler to manage
w.DataHandler <- err
}
w.DataHandler <- err
case <-timer.C:
if !w.IsConnecting() && !w.IsConnected() {
err := w.Connect()
@@ -983,8 +982,8 @@ func (w *Websocket) CanUseAuthenticatedEndpoints() bool {
return w.canUseAuthenticatedEndpoints
}
// isDisconnectionError Determines if the error sent over chan ReadMessageErrors is a disconnection error
func isDisconnectionError(err error) bool {
// IsDisconnectionError Determines if the error sent over chan ReadMessageErrors is a disconnection error
func IsDisconnectionError(err error) bool {
if websocket.IsUnexpectedCloseError(err) {
return true
}