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
use std::{error, fmt, io, str};
#[derive(Debug)]
pub enum Error {
#[cfg(feature = "json-using-serde")]
SerdeJsonError(serde_json::Error),
InvalidUtf8InBody(str::Utf8Error),
IoError(io::Error),
MalformedChunkLength,
MalformedContentLength,
RedirectLocationMissing,
InfiniteRedirectionLoop,
TooManyRedirections,
InvalidUtf8InResponse,
PunycodeConversionFailed,
HttpsFeatureNotEnabled,
PunycodeFeatureNotEnabled,
Other(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Error::*;
match self {
#[cfg(feature = "json-using-serde")]
SerdeJsonError(err) => write!(f, "{}", err),
IoError(err) => write!(f, "{}", err),
InvalidUtf8InBody(err) => write!(f, "{}", err),
MalformedChunkLength => write!(f, "non-usize chunk length with transfer-encoding: chunked"),
MalformedContentLength => write!(f, "non-usize content length"),
RedirectLocationMissing => write!(f, "redirection location header missing"),
InfiniteRedirectionLoop => write!(f, "infinite redirection loop detected"),
TooManyRedirections => write!(f, "too many redirections (over the max)"),
InvalidUtf8InResponse => write!(f, "response contained invalid utf-8 where valid utf-8 was expected"),
HttpsFeatureNotEnabled => write!(f, "request url contains https:// but the https feature is not enabled"),
PunycodeFeatureNotEnabled => write!(f, "non-ascii urls needs to be converted into punycode, and the feature is missing"),
PunycodeConversionFailed => write!(f, "non-ascii url conversion to punycode failed"),
Other(msg) => write!(f, "error in minreq: please open an issue in the minreq repo, include the following: '{}'", msg),
}
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
use Error::*;
match self {
#[cfg(feature = "json-using-serde")]
SerdeJsonError(err) => Some(err),
IoError(err) => Some(err),
InvalidUtf8InBody(err) => Some(err),
_ => None,
}
}
}