reth_seismic_rpc/
error.rs

1//! Error types for the seismic rpc api.
2
3use alloy_rpc_types_eth::BlockError;
4use reth_rpc_eth_api::AsEthApiError;
5use reth_rpc_eth_types::EthApiError;
6use reth_rpc_server_types::result::internal_rpc_err;
7
8#[derive(Debug, thiserror::Error)]
9/// Seismic API error
10pub enum SeismicEthApiError {
11    /// Eth error
12    #[error(transparent)]
13    Eth(#[from] EthApiError),
14    /// Enclave error
15    #[error("enclave error: {0}")]
16    EnclaveError(String),
17}
18
19impl AsEthApiError for SeismicEthApiError {
20    fn as_err(&self) -> Option<&EthApiError> {
21        match self {
22            Self::Eth(err) => Some(err),
23            _ => None,
24        }
25    }
26}
27
28impl From<SeismicEthApiError> for jsonrpsee::types::error::ErrorObject<'static> {
29    fn from(error: SeismicEthApiError) -> Self {
30        match error {
31            SeismicEthApiError::Eth(e) => e.into(),
32            SeismicEthApiError::EnclaveError(e) => internal_rpc_err(format!("enclave error: {e}")),
33        }
34    }
35}
36
37impl From<BlockError> for SeismicEthApiError {
38    fn from(error: BlockError) -> Self {
39        Self::Eth(error.into())
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use crate::error::SeismicEthApiError;
46
47    #[test]
48    fn enclave_error_message() {
49        let err: jsonrpsee::types::error::ErrorObject<'static> =
50            SeismicEthApiError::EnclaveError("test".to_string()).into();
51        assert_eq!(err.message(), "enclave error: test");
52    }
53}