1#[derive(Debug)]
3pub enum CollectionError {
4 CollectionNotFound(String),
6 EndpointNotFound(String),
8 IoError(std::io::Error),
10 JsonError(serde_json::Error),
12 Other(String),
14}
15
16impl std::fmt::Display for CollectionError {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 CollectionError::CollectionNotFound(name) => {
20 write!(f, "Collection not found: {}", name)
21 }
22 CollectionError::EndpointNotFound(name) => write!(f, "Endpoint not found: {}", name),
23 CollectionError::IoError(e) => write!(f, "IO error: {}", e),
24 CollectionError::JsonError(e) => write!(f, "JSON error: {}", e),
25 CollectionError::Other(msg) => write!(f, "{}", msg),
26 }
27 }
28}
29
30impl std::error::Error for CollectionError {}
31
32impl From<std::io::Error> for CollectionError {
33 fn from(err: std::io::Error) -> Self {
34 CollectionError::IoError(err)
35 }
36}
37
38impl From<serde_json::Error> for CollectionError {
39 fn from(err: serde_json::Error) -> Self {
40 CollectionError::JsonError(err)
41 }
42}
43
44impl From<Box<dyn std::error::Error>> for CollectionError {
45 fn from(err: Box<dyn std::error::Error>) -> Self {
46 CollectionError::Other(err.to_string())
47 }
48}
49
50#[derive(Debug)]
52pub enum HttpError {
53 Timeout,
55 ConnectionError(String),
57 RedirectError(String),
59 RequestError(String),
61 ResponseError(String),
63 Other(String),
65}
66
67impl std::fmt::Display for HttpError {
68 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 match self {
70 HttpError::Timeout => write!(f, "Request timed out"),
71 HttpError::ConnectionError(msg) => write!(f, "Connection error: {}", msg),
72 HttpError::RedirectError(msg) => write!(f, "Redirect error: {}", msg),
73 HttpError::RequestError(msg) => write!(f, "Request error: {}", msg),
74 HttpError::ResponseError(msg) => write!(f, "Response error: {}", msg),
75 HttpError::Other(msg) => write!(f, "{}", msg),
76 }
77 }
78}
79
80impl std::error::Error for HttpError {}
81
82impl From<reqwest::Error> for HttpError {
83 fn from(err: reqwest::Error) -> Self {
84 if err.is_timeout() {
85 HttpError::Timeout
86 } else if err.is_connect() {
87 HttpError::ConnectionError(err.to_string())
88 } else if err.is_redirect() {
89 HttpError::RedirectError(err.to_string())
90 } else {
91 HttpError::Other(err.to_string())
92 }
93 }
94}