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
use std::error::Error;
use std::{fmt, io};
use crate::client::response::ParseError;
use crate::error::OAuth2Error;
#[derive(Debug)]
pub enum ClientError {
Io(io::Error),
Url(url::ParseError),
#[cfg(feature = "reqwest-client")]
Reqwest(reqwest::Error),
#[cfg(feature = "hyper-client")]
Http(hyper::http::Error),
#[cfg(feature = "hyper-client")]
Hyper(hyper::Error),
Json(serde_json::Error),
Parse(ParseError),
OAuth2(OAuth2Error),
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", self.source().unwrap())
}
}
impl Error for ClientError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
ClientError::Io(ref err) => Some(err),
ClientError::Url(ref err) => Some(err),
ClientError::Json(ref err) => Some(err),
ClientError::Parse(ref err) => Some(err),
ClientError::OAuth2(ref err) => Some(err),
#[cfg(feature = "reqwest-client")]
ClientError::Reqwest(ref err) => Some(err),
#[cfg(feature = "hyper-client")]
ClientError::Hyper(ref err) => Some(err),
#[cfg(feature = "hyper-client")]
ClientError::Http(ref err) => Some(err),
}
}
}
macro_rules! impl_from {
($v:path, $t:ty) => {
impl From<$t> for ClientError {
fn from(err: $t) -> Self {
$v(err)
}
}
}
}
impl_from!(ClientError::Io, io::Error);
impl_from!(ClientError::Url, url::ParseError);
impl_from!(ClientError::Json, serde_json::Error);
impl_from!(ClientError::Parse, ParseError);
impl_from!(ClientError::OAuth2, OAuth2Error);
#[cfg(feature = "reqwest-client")]
impl_from!(ClientError::Reqwest, reqwest::Error);
#[cfg(feature = "hyper-client")]
impl_from!(ClientError::Http, hyper::http::Error);
#[cfg(feature = "hyper-client")]
impl_from!(ClientError::Hyper, hyper::Error);