ai_proxy/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5    Io(std::io::Error),
6    Http(hyper::Error),
7    Json(serde_json::Error),
8    Yaml(serde_yaml::Error),
9    Reqwest(reqwest::Error),
10    Config(String),
11    Server(String),
12}
13
14impl fmt::Display for Error {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Error::Io(e) => write!(f, "IO error: {}", e),
18            Error::Http(e) => write!(f, "HTTP error: {}", e),
19            Error::Json(e) => write!(f, "JSON error: {}", e),
20            Error::Yaml(e) => write!(f, "YAML error: {}", e),
21            Error::Reqwest(e) => write!(f, "Request error: {}", e),
22            Error::Config(e) => write!(f, "Config error: {}", e),
23            Error::Server(e) => write!(f, "Server error: {}", e),
24        }
25    }
26}
27
28impl std::error::Error for Error {}
29
30impl From<std::io::Error> for Error {
31    fn from(err: std::io::Error) -> Self {
32        Error::Io(err)
33    }
34}
35
36impl From<hyper::Error> for Error {
37    fn from(err: hyper::Error) -> Self {
38        Error::Http(err)
39    }
40}
41
42impl From<serde_json::Error> for Error {
43    fn from(err: serde_json::Error) -> Self {
44        Error::Json(err)
45    }
46}
47
48impl From<serde_yaml::Error> for Error {
49    fn from(err: serde_yaml::Error) -> Self {
50        Error::Yaml(err)
51    }
52}
53
54impl From<reqwest::Error> for Error {
55    fn from(err: reqwest::Error) -> Self {
56        Error::Reqwest(err)
57    }
58}
59
60impl From<http::Error> for Error {
61    fn from(err: http::Error) -> Self {
62        Error::Server(err.to_string())
63    }
64}
65
66pub type Result<T> = std::result::Result<T, Error>;