kobe_client/
error.rs

1use thiserror::Error;
2
3/// Error types for Jito API client
4#[derive(Error, Debug)]
5pub enum KobeApiError {
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    /// API returned an error response
15    #[error("API error: {status_code} - {message}")]
16    ApiError { status_code: u16, message: String },
17
18    /// Invalid parameter provided
19    #[error("Invalid parameter: {0}")]
20    InvalidParameter(String),
21
22    /// Resource not found
23    #[error("Resource not found: {0}")]
24    NotFound(String),
25
26    /// Rate limit exceeded
27    #[error("Rate limit exceeded. Please try again later.")]
28    RateLimitExceeded,
29
30    /// Timeout error
31    #[error("Request timed out")]
32    Timeout,
33
34    /// Invalid URL
35    #[error("Invalid URL: {0}")]
36    InvalidUrl(String),
37
38    /// Other errors
39    #[error("An error occurred: {0}")]
40    Other(String),
41}
42
43impl KobeApiError {
44    /// Create an API error from status code and message
45    pub fn api_error(status_code: u16, message: impl Into<String>) -> Self {
46        KobeApiError::ApiError {
47            status_code,
48            message: message.into(),
49        }
50    }
51
52    /// Create an invalid parameter error
53    pub fn invalid_parameter(message: impl Into<String>) -> Self {
54        KobeApiError::InvalidParameter(message.into())
55    }
56
57    /// Check if error is a rate limit error
58    pub fn is_rate_limit(&self) -> bool {
59        matches!(self, KobeApiError::RateLimitExceeded)
60    }
61
62    /// Check if error is a not found error
63    pub fn is_not_found(&self) -> bool {
64        matches!(self, KobeApiError::NotFound(_))
65    }
66}