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 bcrypt::BcryptError;
use diesel::result::Error as DieselErr;
use std::convert::From;
use std::error::Error as StdError;
use std::fmt;
#[derive(Debug)]
pub enum Error {
DieselError(DieselErr),
PasswordError(BcryptError),
CommunicationError(reqwest::Error),
ParseError(serde_json::error::Error),
AlreadyExists,
NotFound,
InternalError,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::DieselError(ref e) => e.fmt(f),
Error::PasswordError(ref e) => e.fmt(f),
Error::CommunicationError(ref e) => e.fmt(f),
Error::ParseError(ref e) => e.fmt(f),
Error::AlreadyExists => f.write_str("AlreadyExists"),
Error::NotFound => f.write_str("NotFound"),
Error::InternalError => f.write_str("InternalError"),
}
}
}
impl From<serde_json::error::Error> for Error {
fn from(e: serde_json::error::Error) -> Error {
Error::ParseError(e)
}
}
impl From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Error {
Error::CommunicationError(e)
}
}
impl From<DieselErr> for Error {
fn from(e: DieselErr) -> Error {
Error::DieselError(e)
}
}
impl From<BcryptError> for Error {
fn from(e: BcryptError) -> Error {
Error::PasswordError(e)
}
}
impl StdError for Error {}
|