tomusdrw / rust-web3

Ethereum JSON-RPC multi-transport client. Rust implementation of web3 library. ENS address: rust-web3.eth
MIT License
1.46k stars 469 forks source link

Handle json-rpc failure response as root response object for batched requests #692

Closed tadovas closed 1 year ago

tadovas commented 1 year ago

Situation: Some public nodes on various chains reply with the following json body for batched requests:

{ 
  "jsonrpc":"2.0",
  "error":{
     "code":0,
     "message":"we can't execute this request"
  },
  "id":null
}

And since batched method expects Vec\<Output> as a result, serde_json fails to parse response and returns generic and obfuscated error like failed to deserialize response: invalid type: map, expected a sequence at line 1 column 0

Solution: Check for json-rpc error object before parsing response as array of outputs and returns appropriate Rpc error. Test to reproduce the issue and verify the fix is added.

tomusdrw commented 1 year ago

lgtm, thanks!