From 65f7c80fb6c9df253633b9be8ad2e0abb81c79ca Mon Sep 17 00:00:00 2001 From: Valentin Fedoskin Date: Sat, 23 May 2020 17:50:19 +0200 Subject: [PATCH] handle disconnect error --- pkg/notifier/websocket.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/notifier/websocket.go b/pkg/notifier/websocket.go index 5219209..eeb96f8 100644 --- a/pkg/notifier/websocket.go +++ b/pkg/notifier/websocket.go @@ -4,6 +4,7 @@ import ( "github.com/gorilla/websocket" "github.com/sirupsen/logrus" "net/http" + "strings" ) var upgrader = websocket.Upgrader{} @@ -20,10 +21,16 @@ func handleWebsocketRequest(w http.ResponseWriter, r *http.Request) { } }() + logrus.Info("websocket connection is open") + for { mt, message, err := conn.ReadMessage() if err != nil { - logrus.WithError(err).Error("failed to read message") + if strings.Contains(err.Error(), "close 1000") { + logrus.Info("websocket connection is closed") + } else { + logrus.WithError(err).Error("failed to read message") + } break }