Skip to main content

bw_web_api_rs/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum ApiError {
5    /// Error while creating the HTTP client
6    #[error("Failed to create HTTP client: {0}")]
7    ClientCreationError(String),
8
9    /// HTTP request failed
10    #[error("HTTP request failed: {0}")]
11    RequestError(#[from] reqwest::Error),
12
13    /// Failed to deserialize the API response
14    #[error("Failed to deserialize response: {0}")]
15    DeserializationError(String),
16
17    /// API returned an error response
18    #[error("API error (status {status}): {message}")]
19    ApiError { status: u16, message: String },
20
21    /// Invalid input parameters
22    #[error("Invalid input: {0}")]
23    ValidationError(String),
24}
25
26// Implement standard error conversion
27impl From<serde_json::Error> for ApiError {
28    fn from(err: serde_json::Error) -> Self {
29        ApiError::DeserializationError(err.to_string())
30    }
31}