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 {
20        status: u16,
21        message: String,
22    },
23
24    /// Invalid input parameters
25    #[error("Invalid input: {0}")]
26    ValidationError(String),
27}
28
29// Implement standard error conversion
30impl From<serde_json::Error> for ApiError {
31    fn from(err: serde_json::Error) -> Self {
32        ApiError::DeserializationError(err.to_string())
33    }
34}