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
use hyper::StatusCode;
#[derive(Debug)]
pub enum Error {
TimedOut,
StreamClosed,
InvalidParameter(Box<dyn std::error::Error + Send + 'static>),
UnexpectedResponse(StatusCode),
HttpStream(Box<dyn std::error::Error + Send + 'static>),
Eof,
UnexpectedEof,
InvalidLine(String),
InvalidEvent,
MalformedLocationHeader(Box<dyn std::error::Error + Send + 'static>),
MaxRedirectLimitReached(u32),
Unexpected(Box<dyn std::error::Error + Send + 'static>),
}
impl PartialEq<Error> for Error {
fn eq(&self, other: &Error) -> bool {
use Error::*;
if let (InvalidLine(msg1), InvalidLine(msg2)) = (self, other) {
return msg1 == msg2;
} else if let (UnexpectedEof, UnexpectedEof) = (self, other) {
return true;
}
false
}
}
impl Error {
pub fn is_http_stream_error(&self) -> bool {
if let Error::HttpStream(_) = self {
return true;
}
false
}
pub fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::HttpStream(err) => Some(err.as_ref()),
Error::Unexpected(err) => Some(err.as_ref()),
_ => None,
}
}
}
impl<E> From<E> for Error
where
E: std::error::Error + Send + 'static,
{
fn from(e: E) -> Error {
Error::Unexpected(Box::new(e))
}
}
pub type Result<T> = std::result::Result<T, Error>;