easy_http_proxy_server/
error.rs

1//! Error types for the HTTP proxy library
2
3use std::fmt;
4
5/// Error type for the HTTP proxy library
6#[derive(Debug)]
7pub enum ProxyError {
8    /// IO error
9    Io(std::io::Error),
10    /// Hyper error
11    Hyper(hyper::Error),
12    /// Address parsing error
13    AddressParse(std::net::AddrParseError),
14    /// Other error
15    Other(String),
16}
17
18impl fmt::Display for ProxyError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            ProxyError::Io(e) => write!(f, "IO error: {}", e),
22            ProxyError::Hyper(e) => write!(f, "Hyper error: {}", e),
23            ProxyError::AddressParse(e) => write!(f, "Address parse error: {}", e),
24            ProxyError::Other(e) => write!(f, "Error: {}", e),
25        }
26    }
27}
28
29impl std::error::Error for ProxyError {}
30
31impl From<std::io::Error> for ProxyError {
32    fn from(error: std::io::Error) -> Self {
33        ProxyError::Io(error)
34    }
35}
36
37impl From<hyper::Error> for ProxyError {
38    fn from(error: hyper::Error) -> Self {
39        ProxyError::Hyper(error)
40    }
41}
42
43impl From<std::net::AddrParseError> for ProxyError {
44    fn from(error: std::net::AddrParseError) -> Self {
45        ProxyError::AddressParse(error)
46    }
47}
48
49impl From<&str> for ProxyError {
50    fn from(error: &str) -> Self {
51        ProxyError::Other(error.to_string())
52    }
53}