From ec8d739da0ca72a912161aab728dacb373d7b358 Mon Sep 17 00:00:00 2001 From: PrashantBtkl Date: Tue, 11 Aug 2026 20:12:58 +0530 Subject: [PATCH] fix(ws): surface HTTP status/body on relay dial failure Bad-handshake errors from the relay were logged as an opaque "websocket: bad handshake" with no indication of why (relay down, auth rejected, rate limited, etc.). gorilla/websocket returns the HTTP response alongside ErrBadHandshake; capture and log its status code and body instead of discarding it. --- pkg/ws/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/ws/client.go b/pkg/ws/client.go index eea1cce..2b648a5 100644 --- a/pkg/ws/client.go +++ b/pkg/ws/client.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io" "log/slog" "net/http" "sync" @@ -142,8 +143,13 @@ func (c *Client) connectAndServe(ctx context.Context) error { c.logger.Info("connecting to relay", "url", c.relayURL) - conn, _, err := websocket.DefaultDialer.DialContext(ctx, c.relayURL, header) + conn, resp, err := websocket.DefaultDialer.DialContext(ctx, c.relayURL, header) if err != nil { + if resp != nil { + body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024)) + resp.Body.Close() // nolint:errcheck + return fmt.Errorf("dial failed: %w (status=%d body=%q)", err, resp.StatusCode, body) + } return fmt.Errorf("dial failed: %w", err) }