reqwest_builder/
errors.rs

1/// Custom error types for the reqwest-builder library
2#[derive(Debug, Clone, PartialEq)]
3pub enum ReqwestBuilderError {
4    /// Error serializing data to JSON
5    SerializationError(String),
6    /// Error with header name or value
7    HeaderError {
8        key: String,
9        value: String,
10        source: String,
11    },
12    /// Error constructing URL
13    UrlError(String),
14    /// File I/O error
15    IoError(String),
16    /// Invalid request configuration
17    InvalidRequest(String),
18}
19
20impl std::fmt::Display for ReqwestBuilderError {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        match self {
23            ReqwestBuilderError::SerializationError(msg) => {
24                write!(f, "Serialization error: {}", msg)
25            }
26            ReqwestBuilderError::HeaderError { key, value, source } => {
27                write!(f, "Header error for '{}': '{}' - {}", key, value, source)
28            }
29            ReqwestBuilderError::UrlError(msg) => write!(f, "URL error: {}", msg),
30            ReqwestBuilderError::IoError(msg) => write!(f, "I/O error: {}", msg),
31            ReqwestBuilderError::InvalidRequest(msg) => write!(f, "Invalid request: {}", msg),
32        }
33    }
34}
35
36impl std::error::Error for ReqwestBuilderError {}
37
38impl From<std::io::Error> for ReqwestBuilderError {
39    fn from(err: std::io::Error) -> Self {
40        ReqwestBuilderError::IoError(err.to_string())
41    }
42}
43
44impl From<serde_json::Error> for ReqwestBuilderError {
45    fn from(err: serde_json::Error) -> Self {
46        ReqwestBuilderError::SerializationError(err.to_string())
47    }
48}