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