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
use hyper::Error as HttpError;
use serde_json::error::Error as SerdeError;
use std::io::Error as IoError;
#[derive(Deserialize)]
pub(crate) struct ApiError {
pub error: String,
pub error_description: String,
}
error_chain! {
errors {
Api(error: String, error_description: String) {
display("{}: '{}'", error, error_description)
description(error_description)
}
}
foreign_links {
Codec(SerdeError) #[doc = "Represents serialization related errors"];
Http(HttpError) #[doc = "Represents HTTP protocol level errors"];
IO(IoError) #[doc = "Represents generally IO errors"];
}
}
#[cfg(test)]
mod tests {
use super::ErrorKind;
#[test]
fn api_description() {
assert_eq!(
ErrorKind::Api("foobar".into(), "it happened".into()).description(),
"it happened"
)
}
#[test]
fn api_display() {
assert_eq!(
ErrorKind::Api("foobar".into(), "it happened".into()).to_string(),
"foobar: 'it happened'"
)
}
}