Skip to content

Commit

Permalink
jsonrpc error check
Browse files Browse the repository at this point in the history
  • Loading branch information
klaidliadon committed Sep 3, 2024
1 parent 229891a commit fac141e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ethrpc/ethrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"sync/atomic"

"github.com/0xsequence/ethkit/ethrpc/jsonrpc"
"github.com/0xsequence/ethkit/go-ethereum"
"github.com/0xsequence/ethkit/go-ethereum/accounts/abi/bind"
"github.com/0xsequence/ethkit/go-ethereum/common"
Expand Down Expand Up @@ -113,6 +114,10 @@ func (p *Provider) Do(ctx context.Context, calls ...Call) ([]byte, error) {
}

if (res.StatusCode < 200 || res.StatusCode > 299) && res.StatusCode != 401 {
msg := jsonrpc.Message{}
if err := json.Unmarshal(body, &msg); err == nil && msg.Error != nil {
return body, superr.Wrap(ErrRequestFail, msg.Error)
}
if len(body) > 100 {
body = body[:100]
}
Expand Down

0 comments on commit fac141e

Please sign in to comment.