Skip to content

Commit

Permalink
handle disconnect error
Browse files Browse the repository at this point in the history
  • Loading branch information
slamdev committed May 23, 2020
1 parent 05a935a commit 65f7c80
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/notifier/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"net/http"
"strings"
)

var upgrader = websocket.Upgrader{}
Expand All @@ -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
}

Expand Down

0 comments on commit 65f7c80

Please sign in to comment.