clob_client_rust/
errors.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum ClobError {
5 #[error("Signer is needed to interact with this endpoint!")]
6 L1AuthUnavailable,
7
8 #[error("API Credentials are needed to interact with this endpoint!")]
9 L2AuthNotAvailable,
10
11 #[error("Builder API Credentials needed to interact with this endpoint!")]
12 BuilderAuthNotAvailable,
13
14 #[error("Builder key auth failed!")]
15 BuilderAuthFailed,
16
17 #[error("HTTP {status} {method} {endpoint}: {body}")]
19 HttpError {
20 status: u16,
21 method: String,
22 endpoint: String,
23 body: String,
24 },
25
26 #[error(transparent)]
27 Reqwest(#[from] reqwest::Error),
28
29 #[error(transparent)]
30 SerdeJson(#[from] serde_json::Error),
31
32 #[error("Other error: {0}")]
33 Other(String),
34}
35
36impl ClobError {
37 pub fn http_status(&self) -> Option<u16> {
39 match self {
40 ClobError::HttpError { status, .. } => Some(*status),
41 _ => None,
42 }
43 }
44
45 pub fn is_rate_limited(&self) -> bool {
47 self.http_status() == Some(429)
48 }
49}