From 685761558562720fd9f112eff198919b9d2256b3 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 24 Oct 2024 07:25:48 +0200 Subject: [PATCH] fix: no error on normal websocket closure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ignore error for normal closure - log any other errors encountered during message processing - reorder import statements 🤖 --- internal/websocket/receive.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/websocket/receive.go b/internal/websocket/receive.go index 9493caf..889a8ce 100644 --- a/internal/websocket/receive.go +++ b/internal/websocket/receive.go @@ -1,10 +1,10 @@ package websocket import ( - "git.smsvc.net/pomodoro/ChronoTomato/internal/notifications" - "git.smsvc.net/pomodoro/ChronoTomato/internal/shared" "encoding/json" "fmt" + "git.smsvc.net/pomodoro/ChronoTomato/internal/notifications" + "git.smsvc.net/pomodoro/ChronoTomato/internal/shared" "github.com/charmbracelet/log" "github.com/gorilla/websocket" ) @@ -18,6 +18,11 @@ func ProcessServerMessages(conn *websocket.Conn) { for { _, message, err := conn.ReadMessage() if err != nil { + if websocket.IsCloseError(err, 1000) { + // Ignore normal closure and exit gracefully + return + } + // Log any other errors fmt.Println() log.Error("Read error!", "reason", err) return