Skip to content

Commit

Permalink
handle status codes other than ok in http (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar committed Jul 12, 2023
1 parent 8230f57 commit df37ddd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jsonrpc/transport/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transport

import (
"encoding/json"
"fmt"

"github.com/umbracle/ethgo/jsonrpc/codec"
"github.com/valyala/fasthttp"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit df37ddd

Please sign in to comment.