mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 07:26:53 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user