1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, Error)]
10pub enum Error {
11 #[error("Configuration error: {0}")]
13 Config(String),
14
15 #[error("I/O error: {source}")]
17 Io {
18 #[from]
20 source: std::io::Error,
21 },
22
23 #[error("Network error: {0}")]
25 Network(String),
26
27 #[error("Serialization error: {0}")]
29 Serialization(String),
30
31 #[error("Protocol error: {0}")]
33 Protocol(String),
34
35 #[error("Authentication failed: {0}")]
37 Auth(String),
38
39 #[error("Operation timed out")]
41 Timeout,
42
43 #[error("Server error: {0}")]
45 Server(String),
46
47
48 #[error("Unexpected error: {0}")]
50 Other(String),
51}
52
53impl From<reqwest::Error> for Error {
54 fn from(err: reqwest::Error) -> Self {
55 if err.is_timeout() {
56 Error::Timeout
57 } else if err.is_connect() {
58 Error::Network(format!("Connection error: {}", err))
59 } else if err.is_decode() {
60 Error::Serialization(format!("Failed to decode response: {}", err))
61 } else {
62 Error::Network(err.to_string())
63 }
64 }
65}
66
67impl From<serde_json::Error> for Error {
68 fn from(err: serde_json::Error) -> Self {
69 Error::Serialization(err.to_string())
70 }
71}
72
73impl From<url::ParseError> for Error {
74 fn from(err: url::ParseError) -> Self {
75 Error::Config(format!("Invalid URL: {}", err))
76 }
77}