1pub mod api;
2pub use api::*;
3
4#[derive(Debug)]
5pub struct ApiError {
6 pub status_code: u16,
7 pub url: String,
8 pub request_body: Option<String>,
9 pub response_body: String,
10 pub response_headers: std::collections::HashMap<String, String>,
11 pub timestamp: Option<String>,
12 pub path: Option<String>,
13 pub message: Option<String>,
14 pub error_code: Option<String>,
15 pub error: Option<String>,
16}
17
18impl std::fmt::Display for ApiError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 if let Some(msg) = &self.message {
21 write!(
22 f,
23 "API Error [{}]: {} (code: {}) - {} | <{}>",
24 self.status_code,
25 msg,
26 self.error_code.as_deref().unwrap_or("unknown"),
27 self.error.as_deref().unwrap_or("unknown"),
28 self.request_body.as_deref().unwrap_or("unknown")
29 )
30 } else {
31 write!(
32 f,
33 "HTTP {} from {}: {} (code: {}) - {}",
34 self.status_code,
35 self.url,
36 self.response_body,
37 self.error_code.as_deref().unwrap_or("unknown"),
38 self.error.as_deref().unwrap_or("unknown")
39 )
40 }
41 }
42}
43
44impl std::error::Error for ApiError {}