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
use std::io;
use std::fmt;
use reqwest;
use serde_json;
use client::Status;
#[derive(PartialEq, Eq, Clone, Debug)]
pub enum AuthyError {
BadRequest(Status),
UnauthorizedKey(Status),
Forbidden(Status),
UserNotFound(Status),
TooManyRequests(Status),
InternalServerError(Status),
ServiceUnavailable,
IoError(String),
JsonParseError(String),
RequestError(String),
InvalidServerResponse,
}
impl fmt::Display for AuthyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use AuthyError::*;
match *self {
BadRequest(ref s) => write!(f, "Bad Request: {}", s.message),
UnauthorizedKey(ref s) => write!(f, "Unauthorized API Key: {}", s.message),
Forbidden(ref s) => write!(f, "Forbidden: {}", s.message),
UserNotFound(ref s) => write!(f, "User Not Found: {}", s.message),
TooManyRequests(ref s) => write!(f, "Too Many Requests: {}", s.message),
InternalServerError(ref s) => write!(f, "Internal Server Error: {}", s.message),
ServiceUnavailable => write!(f, "Service Unavailable reported by authy service"),
IoError(ref s) => write!(f, "IO Error: {}", s),
JsonParseError(ref s) => write!(f, "Json parsing error: {}", s),
RequestError(ref s) => write!(f, "Request error: {}", s),
InvalidServerResponse => write!(f, "Server returned an invalid response"),
}
}
}
impl From<reqwest::Error> for AuthyError {
fn from(e: reqwest::Error) -> Self {
AuthyError::RequestError(e.to_string())
}
}
impl From<serde_json::Error> for AuthyError {
fn from(e: serde_json::Error) -> Self {
AuthyError::JsonParseError(e.to_string())
}
}
impl From<io::Error> for AuthyError {
fn from(e: io::Error) -> Self {
AuthyError::IoError(e.to_string())
}
}