Skip to content

Commit

Permalink
ws: return body (if any) in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Feb 11, 2024
1 parent bf98559 commit 6fe3aea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rpc/ws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 6fe3aea

Please sign in to comment.