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
use std;
use serde_json::Error as json_error;
use std::io::Error as io_error;
use smpl_jwt::error::JwtErr as jwt_error;
use reqwest::Error as reqwest_error;
use auth::TokenErr as token_error;
macro_rules! impl_from {
($type_: ident, $enum_ty: ident) => {
impl From<$type_> for GOErr {
fn from(e: $type_) -> GOErr {
GOErr::$enum_ty(e)
}
}
}
}
#[derive(Debug)]
pub enum GOErr {
Json(json_error),
Io(io_error),
JWT(jwt_error),
Re(reqwest_error),
TokenErr(token_error),
Unknown
}
impl_from!(json_error, Json);
impl_from!(io_error, Io);
impl_from!(reqwest_error, Re);
impl_from!(jwt_error, JWT);
impl_from!(token_error, TokenErr);
impl std::fmt::Display for GOErr {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
GOErr::Json(ref e) => e.fmt(f),
GOErr::Io(ref e) => e.fmt(f),
GOErr::JWT(ref e) => e.fmt(f),
GOErr::TokenErr(ref e) => e.fmt(f),
GOErr::Re(ref e) => e.fmt(f),
GOErr::Unknown => write!(f, "An unknown error has occurred"),
}
}
}
impl std::error::Error for GOErr {
fn description(&self) -> &str {
match *self {
GOErr::Json(ref e) => e.description(),
GOErr::Io(ref e) => e.description(),
GOErr::JWT(ref e) => e.description(),
GOErr::TokenErr(ref e) => e.description(),
GOErr::Re(ref e) => e.description(),
GOErr::Unknown => "unknown error",
}
}
}