tempo_node/rpc/dex/
error.rs1use alloy_eips::BlockId;
2use alloy_primitives::B256;
3use jsonrpsee::types::ErrorObject;
4use reth_rpc_eth_types::{EthApiError, error::ToRpcError};
5use tempo_precompiles::error::TempoPrecompileError;
6
7#[derive(Debug, thiserror::Error)]
9pub enum DexApiError {
10 #[error(transparent)]
12 Precompile(#[from] TempoPrecompileError),
13
14 #[error("header not found for block {0:?}")]
16 HeaderNotFound(BlockId),
17
18 #[error("internal node error: failed to get header: {0}")]
21 Provider(#[source] Box<dyn std::error::Error + Send + Sync>),
22
23 #[error("internal node error: failed to create EVM")]
26 CreateEvm(#[source] Box<dyn std::error::Error + Send + Sync>),
27
28 #[error("invalid order cursor: expected hex string, got {0}")]
30 InvalidOrderCursor(String),
31
32 #[error("invalid order cursor: failed to parse hex value")]
34 ParseOrderCursor(#[from] std::num::ParseIntError),
35
36 #[error("invalid orderbook cursor: failed to parse as B256")]
38 InvalidOrderbookCursor(String),
39
40 #[error("orderbook cursor {0} not found in available books")]
42 OrderbookCursorNotFound(B256),
43}
44
45impl DexApiError {
46 const fn error_code(&self) -> i32 {
48 match self {
49 Self::InvalidOrderbookCursor(_)
50 | Self::InvalidOrderCursor(_)
51 | Self::ParseOrderCursor(_) => jsonrpsee::types::error::INVALID_PARAMS_CODE,
52 _ => jsonrpsee::types::error::INTERNAL_ERROR_CODE,
53 }
54 }
55}
56
57impl From<DexApiError> for EthApiError {
58 fn from(err: DexApiError) -> Self {
59 match err {
60 DexApiError::HeaderNotFound(block_id) => Self::HeaderNotFound(block_id),
61 other => Self::other(other),
63 }
64 }
65}
66
67impl ToRpcError for DexApiError {
68 fn to_rpc_error(&self) -> ErrorObject<'static> {
69 ErrorObject::owned(self.error_code(), self.to_string(), None::<()>)
70 }
71}
72
73impl From<DexApiError> for ErrorObject<'static> {
74 fn from(value: DexApiError) -> Self {
75 value.to_rpc_error()
76 }
77}