From 6fe3aea02e3660d620433444df033fc3fe6e64c1 Mon Sep 17 00:00:00 2001 From: gagliardetto Date: Sun, 11 Feb 2024 20:37:59 +0100 Subject: [PATCH] ws: return body (if any) in case of error --- rpc/ws/client.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rpc/ws/client.go b/rpc/ws/client.go index b1ca6224..261b4532 100644 --- a/rpc/ws/client.go +++ b/rpc/ws/client.go @@ -84,9 +84,16 @@ func ConnectWithOptions(ctx context.Context, rpcEndpoint string, opt *Options) ( if opt != nil && opt.HttpHeader != nil && len(opt.HttpHeader) > 0 { httpHeader = opt.HttpHeader } - c.conn, _, err = dialer.DialContext(ctx, rpcEndpoint, httpHeader) + var resp *http.Response + c.conn, resp, err = dialer.DialContext(ctx, rpcEndpoint, httpHeader) if err != nil { - return nil, fmt.Errorf("new ws client: dial: %w", err) + if resp != nil { + body, _ := io.ReadAll(resp.Body) + err = fmt.Errorf("new ws client: dial: %w, status: %s, body: %q", err, resp.Status, string(body)) + } else { + err = fmt.Errorf("new ws client: dial: %w", err) + } + return nil, err } c.connCtx, c.connCtxCancel = context.WithCancel(context.Background())