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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use std::io;
use actix_connect::resolver::ResolveError;
use derive_more::{Display, From};
#[cfg(feature = "openssl")]
use actix_connect::ssl::openssl::{HandshakeError, SslError};
use crate::error::{Error, ParseError, ResponseError};
use crate::http::{Error as HttpError, StatusCode};
#[derive(Debug, Display, From)]
pub enum ConnectError {
#[display(fmt = "SSL is not supported")]
SslIsNotSupported,
#[cfg(feature = "openssl")]
#[display(fmt = "{}", _0)]
SslError(SslError),
#[cfg(feature = "openssl")]
#[display(fmt = "{}", _0)]
SslHandshakeError(String),
#[display(fmt = "Failed resolving hostname: {}", _0)]
Resolver(ResolveError),
#[display(fmt = "No dns records found for the input")]
NoRecords,
#[display(fmt = "{}", _0)]
H2(h2::Error),
#[display(fmt = "Timeout out while establishing connection")]
Timeout,
#[display(fmt = "Internal error: connector has been disconnected")]
Disconnected,
#[display(fmt = "Connector received `Connect` method with unresolved host")]
Unresolverd,
#[display(fmt = "{}", _0)]
Io(io::Error),
}
impl From<actix_connect::ConnectError> for ConnectError {
fn from(err: actix_connect::ConnectError) -> ConnectError {
match err {
actix_connect::ConnectError::Resolver(e) => ConnectError::Resolver(e),
actix_connect::ConnectError::NoRecords => ConnectError::NoRecords,
actix_connect::ConnectError::InvalidInput => panic!(),
actix_connect::ConnectError::Unresolverd => ConnectError::Unresolverd,
actix_connect::ConnectError::Io(e) => ConnectError::Io(e),
}
}
}
#[cfg(feature = "openssl")]
impl<T: std::fmt::Debug> From<HandshakeError<T>> for ConnectError {
fn from(err: HandshakeError<T>) -> ConnectError {
ConnectError::SslHandshakeError(format!("{:?}", err))
}
}
#[derive(Debug, Display, From)]
pub enum InvalidUrl {
#[display(fmt = "Missing url scheme")]
MissingScheme,
#[display(fmt = "Unknown url scheme")]
UnknownScheme,
#[display(fmt = "Missing host name")]
MissingHost,
#[display(fmt = "Url parse error: {}", _0)]
HttpError(http::Error),
}
#[derive(Debug, Display, From)]
pub enum SendRequestError {
#[display(fmt = "Invalid URL: {}", _0)]
Url(InvalidUrl),
#[display(fmt = "Failed to connect to host: {}", _0)]
Connect(ConnectError),
Send(io::Error),
Response(ParseError),
#[display(fmt = "{}", _0)]
Http(HttpError),
#[display(fmt = "{}", _0)]
H2(h2::Error),
#[display(fmt = "Timeout out while waiting for response")]
Timeout,
#[display(fmt = "Tunnels are not supported for http2 connection")]
TunnelNotSupported,
Body(Error),
}
impl ResponseError for SendRequestError {
fn status_code(&self) -> StatusCode {
match *self {
SendRequestError::Connect(ConnectError::Timeout) => {
StatusCode::GATEWAY_TIMEOUT
}
SendRequestError::Connect(_) => StatusCode::BAD_REQUEST,
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
#[derive(Debug, Display, From)]
pub enum FreezeRequestError {
#[display(fmt = "Invalid URL: {}", _0)]
Url(InvalidUrl),
#[display(fmt = "{}", _0)]
Http(HttpError),
}
impl From<FreezeRequestError> for SendRequestError {
fn from(e: FreezeRequestError) -> Self {
match e {
FreezeRequestError::Url(e) => e.into(),
FreezeRequestError::Http(e) => e.into(),
}
}
}