ai_lib/transport/
error.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
9pub enum TransportError {
10 #[error("HTTP request failed: {0}")]
11 HttpError(#[from] reqwest::Error),
12
13 #[error("JSON serialization/deserialization failed: {0}")]
14 JsonError(#[from] serde_json::Error),
15
16 #[error("Invalid URL: {0}")]
17 InvalidUrl(String),
18
19 #[error("Authentication failed: {0}")]
20 AuthenticationError(String),
21
22 #[error("Rate limit exceeded")]
23 RateLimitExceeded,
24
25 #[error("Server error: {status} - {message}")]
26 ServerError { status: u16, message: String },
27
28 #[error("Client error: {status} - {message}")]
29 ClientError { status: u16, message: String },
30
31 #[error("Timeout error: {0}")]
32 Timeout(String),
33}
34
35impl TransportError {
36 pub fn from_status(status: u16, message: String) -> Self {
38 match status {
39 400..=499 => Self::ClientError { status, message },
40 500..=599 => Self::ServerError { status, message },
41 _ => Self::InvalidUrl(format!("Unexpected status code: {}", status)),
42 }
43 }
44}