alloy_rpc_types_eth/
error.rs

1//! Commonly used errors for the `eth_` namespace.
2
3/// List of JSON-RPC error codes
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum EthRpcErrorCode {
6    /// Failed to send transaction, See also <https://github.com/MetaMask/eth-rpc-errors/blob/main/src/error-constants.ts>
7    TransactionRejected,
8    /// Custom geth error code, <https://github.com/vapory-legacy/wiki/blob/master/JSON-RPC-Error-Codes-Improvement-Proposal.md>
9    ExecutionError,
10    /// <https://eips.ethereum.org/EIPS/eip-1898>
11    InvalidInput,
12    /// Thrown when a block wasn't found <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1898.md>
13    /// > If the block is not found, the callee SHOULD raise a JSON-RPC error (the recommended
14    /// > error code is -32001: Resource not found).
15    ResourceNotFound,
16    /// Thrown when querying for `finalized` or `safe` block before the merge transition is
17    /// finalized, <https://github.com/ethereum/execution-apis/blob/6d17705a875e52c26826124c2a8a15ed542aeca2/src/schemas/block.yaml#L109>
18    UnknownBlock,
19}
20
21impl EthRpcErrorCode {
22    /// Returns the error code as `i32`
23    pub const fn code(&self) -> i32 {
24        match *self {
25            Self::TransactionRejected => -32003,
26            Self::ExecutionError => 3,
27            Self::InvalidInput => -32000,
28            Self::ResourceNotFound => -32001,
29            Self::UnknownBlock => -39001,
30        }
31    }
32}