summaryrefslogtreecommitdiff
path: root/src/error.rs
blob: 523922a0b48f4374798010da6df56a144c1a737d (plain)
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
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),
    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::AlreadyExists => f.write_str("AlreadyExists"),
            Error::NotFound => f.write_str("NotFound"),
            Error::InternalError => f.write_str("InternalError"),
        }
    }
}

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 {}