From fb09670fd1c1f96c8679ca538ea70d66be240441 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 23 Nov 2022 11:25:05 +0300 Subject: [PATCH] rpcclient: extract more detailed server-side on WS connection problem If available. Fixes #2818. --- pkg/rpcclient/wsclient.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/rpcclient/wsclient.go b/pkg/rpcclient/wsclient.go index 3e15eff8d..48f3842fd 100644 --- a/pkg/rpcclient/wsclient.go +++ b/pkg/rpcclient/wsclient.go @@ -365,6 +365,15 @@ func NewWS(ctx context.Context, endpoint string, opts Options) (*WSClient, error defer resp.Body.Close() // Not exactly required by websocket, but let's do this for bodyclose checker. } if err != nil { + if resp != nil && resp.Body != nil { + var srvErr neorpc.HeaderAndError + + dec := json.NewDecoder(resp.Body) + decErr := dec.Decode(&srvErr) + if decErr == nil && srvErr.Error != nil { + err = srvErr.Error + } + } return nil, err } wsc := &WSClient{