Skip to content

Commit 9871d43

Browse files
Fix error reporting to avoid missing the actual error
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
1 parent fcaa664 commit 9871d43

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/wsclient/wsclient.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,18 @@ func (w *wsClient) connect(initial bool) error {
375375
var res *http.Response
376376
w.wsconn, res, err = w.wsdialer.DialContext(w.ctx, w.url, w.headers)
377377
if err != nil {
378-
var b []byte
378+
errMsg := err.Error()
379379
var status = -1
380380
if res != nil {
381-
b, _ = io.ReadAll(res.Body)
381+
b, readErr := io.ReadAll(res.Body)
382382
res.Body.Close()
383+
if readErr == nil && len(b) > 0 {
384+
// The info we need is what the server returned and the status
385+
errMsg = string(b)
386+
}
383387
status = res.StatusCode
384388
}
385-
l.Warnf("WS %s connect attempt %d failed [%d]: %s", w.url, attempt, status, string(b))
389+
l.Warnf("WS %s connect attempt %d failed [%d]: %s", w.url, attempt, status, errMsg)
386390
return retry, i18n.WrapError(w.ctx, err, i18n.MsgWSConnectFailed)
387391
}
388392

0 commit comments

Comments
 (0)