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
use std::fmt;
use reqwest_mock::header::InvalidHeaderValue;
pub type Result<T> = ::std::result::Result<T, Error>;
#[derive(Debug, PartialEq)]
pub enum Error {
AboveLimit(String, u64, u64),
Http(u16),
Serial(String),
PostDeserialization(String, String),
CannotSendRequest(String),
CannotCreateClient(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::AboveLimit(option, value, max) => write!(
f,
"{}:{} is above the maximum value allowed in this context ({})",
option, value, max
),
Error::Http(code) => write!(f, "HTTP error: {}", code),
Error::Serial(msg) => write!(f, "Serialization error: {}", msg),
Error::PostDeserialization(k, v) => {
write!(f, "Post JSON: invalid value for field \"{}\": {}", k, v)
}
Error::CannotSendRequest(msg) => write!(f, "Couldn't send request: {}", msg),
Error::CannotCreateClient(msg) => write!(f, "Couldn't create client: {}", msg),
}
}
}
impl From<InvalidHeaderValue> for Error {
fn from(e: InvalidHeaderValue) -> Error {
Error::CannotCreateClient(format!("Invalid header value: {}", e))
}
}