tomusdrw / rust-web3

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

Report HTTP failure codes as RPC errors if returned for an RPC call #585

Closed marmistrz closed 2 years ago

marmistrz commented 2 years ago

At least in the Alchemy JSON RPC API over HTTP, rate limit errors are returned as HTTP 429. Currently these errors are converted to Error::Transport(String) and it's not possible to cleanly access the status code. Moreover, Error::Transport also means errors like failure to deserialize, whose handling will be completely different than handling of capacity limits or rate limit.

This PR changes representations of the errors returned in execute_rpc to rpc::error::Error. Since the HTTP error codes aren't any of the variants defined by jsonrpc-core, the error code will be ErrorCode::ServerError(i64).

cf. https://docs.alchemy.com/alchemy/documentation/error-reference

marmistrz commented 2 years ago

Ping, what do you think about the new implementation?