From f9b9b1de53402df666d7bddb68e5c6d7441e51ff Mon Sep 17 00:00:00 2001 From: Igor Crevar Date: Wed, 5 Jul 2023 15:32:11 +0200 Subject: [PATCH] handle status codes other than ok in http --- jsonrpc/transport/http.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jsonrpc/transport/http.go b/jsonrpc/transport/http.go index 4b4627e2..01c72a66 100644 --- a/jsonrpc/transport/http.go +++ b/jsonrpc/transport/http.go @@ -2,6 +2,7 @@ package transport import ( "encoding/json" + "fmt" "github.com/umbracle/ethgo/jsonrpc/codec" "github.com/valyala/fasthttp" @@ -66,6 +67,10 @@ func (h *HTTP) Call(method string, out interface{}, params ...interface{}) error return err } + if sc := res.StatusCode(); sc != fasthttp.StatusOK { + return fmt.Errorf("status code is %d. response = %s", sc, string(res.Body())) + } + // Decode json-rpc response var response codec.Response if err := json.Unmarshal(res.Body(), &response); err != nil {