1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum KobeApiError {
6 #[error("HTTP request failed: {0}")]
8 HttpError(#[from] reqwest::Error),
9
10 #[error("JSON error: {0}")]
12 JsonError(#[from] serde_json::Error),
13
14 #[error("API error: {status_code} - {message}")]
16 ApiError { status_code: u16, message: String },
17
18 #[error("Invalid parameter: {0}")]
20 InvalidParameter(String),
21
22 #[error("Resource not found: {0}")]
24 NotFound(String),
25
26 #[error("Rate limit exceeded. Please try again later.")]
28 RateLimitExceeded,
29
30 #[error("Request timed out")]
32 Timeout,
33
34 #[error("Invalid URL: {0}")]
36 InvalidUrl(String),
37
38 #[error("An error occurred: {0}")]
40 Other(String),
41}
42
43impl KobeApiError {
44 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 pub fn invalid_parameter(message: impl Into<String>) -> Self {
54 KobeApiError::InvalidParameter(message.into())
55 }
56
57 pub fn is_rate_limit(&self) -> bool {
59 matches!(self, KobeApiError::RateLimitExceeded)
60 }
61
62 pub fn is_not_found(&self) -> bool {
64 matches!(self, KobeApiError::NotFound(_))
65 }
66}