Skip to main content

rs_clob_client_v2/
errors.rs

1use thiserror::Error;
2
3/// Errors that can occur when using the CLOB client
4#[derive(Error, Debug)]
5pub enum ClobError {
6    /// HTTP request error
7    #[error("HTTP request failed: {0}")]
8    HttpError(#[from] reqwest::Error),
9
10    /// JSON serialization/deserialization error
11    #[error("JSON error: {0}")]
12    JsonError(#[from] serde_json::Error),
13
14    /// Authentication error - L1 (wallet signature required)
15    #[error("Signer is needed to interact with this endpoint")]
16    L1AuthUnavailable,
17
18    /// Authentication error - L2 (API credentials required)
19    #[error("API Credentials are needed to interact with this endpoint")]
20    L2AuthNotAvailable,
21
22    /// Builder authentication error
23    #[error("Builder API Credentials needed to interact with this endpoint")]
24    BuilderAuthNotAvailable,
25
26    /// Builder authentication failed
27    #[error("Builder key auth failed")]
28    BuilderAuthFailed,
29
30    /// Invalid price
31    #[error("Invalid price ({price}), min: {min} - max: {max}")]
32    InvalidPrice { price: f64, min: f64, max: f64 },
33
34    /// Invalid tick size
35    #[error("Invalid tick size ({tick_size}), minimum for the market is {min_tick_size}")]
36    InvalidTickSize {
37        tick_size: String,
38        min_tick_size: String,
39    },
40
41    /// No orderbook available
42    #[error("No orderbook available")]
43    NoOrderbook,
44
45    /// No match in orderbook
46    #[error("No match found in orderbook")]
47    NoMatch,
48
49    /// Ethereum wallet error
50    #[error("Ethereum wallet error: {0}")]
51    WalletError(String),
52
53    /// EIP-712 signing error
54    #[error("EIP-712 signing error: {0}")]
55    SigningError(String),
56
57    /// Base64 decoding error
58    #[error("Base64 decode error: {0}")]
59    Base64Error(#[from] base64::DecodeError),
60
61    /// Invalid configuration
62    #[error("Invalid configuration: {0}")]
63    ConfigError(String),
64
65    /// API error response
66    #[error("API error: {message}")]
67    ApiError { message: String, status: u16 },
68
69    /// Generic error
70    #[error("{0}")]
71    Other(String),
72}
73
74/// Result type alias for CLOB operations
75pub type ClobResult<T> = Result<T, ClobError>;