http_type/request/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::{
    error::Error as StdError,
    fmt::{self, Display},
};

#[derive(Debug)]
pub enum Error {
    HttpReadError,
    InvalidHttpRequest,
    InvalidUrl,
    TcpStreamConnectError,
    RequestError,
    MethodsNotSupport,
    ReadConnectionError,
    TlsConnectorBuildError,
    SetReadTimeoutError,
    SetWriteTimeoutError,
    TlsStreamConnectError,
    MaxRedirectTimes,
    RedirectUrlDeadLoop,
    RedirectInvalidUrl,
    NeedOpenRedirect,
    Unknown,
}

impl StdError for Error {}

impl Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::HttpReadError => write!(f, "Http read error"),
            Self::InvalidHttpRequest => write!(f, "Invalid http request"),
            Self::InvalidUrl => write!(f, "Invalid URL"),
            Self::TcpStreamConnectError => write!(f, "TCP Stream Connection Error"),
            Self::RequestError => write!(f, "Request Error"),
            Self::MethodsNotSupport => write!(f, "Unsupported HTTP Method"),
            Self::ReadConnectionError => write!(f, "Connection Read Error"),
            Self::TlsConnectorBuildError => write!(f, "TLS Connector Build Error"),
            Self::SetReadTimeoutError => write!(f, "Failed to Set Read Timeout"),
            Self::SetWriteTimeoutError => write!(f, "Failed to Set Write Timeout"),
            Self::TlsStreamConnectError => write!(f, "TLS Stream Connection Error"),
            Self::MaxRedirectTimes => write!(f, "Max Redirect Times"),
            Self::RedirectUrlDeadLoop => write!(f, "Redirect URL Dead Loop"),
            Self::RedirectInvalidUrl => write!(f, "Redirect Invalid Url"),
            Self::NeedOpenRedirect => write!(f, "Need Open Redirect"),
            Self::Unknown => write!(f, "{}", "Unknown"),
        }
    }
}