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
use std::fmt;

use failure::*;

pub type TokenInfoResult<T> = ::std::result::Result<T, TokenInfoError>;

#[derive(Debug)]
pub struct TokenInfoError {
    inner: Context<TokenInfoErrorKind>,
}

impl TokenInfoError {
    pub fn kind(&self) -> &TokenInfoErrorKind {
        &self.inner.get_context()
    }
}

impl Fail for TokenInfoError {
    fn cause(&self) -> Option<&Fail> {
        self.inner.cause()
    }

    fn backtrace(&self) -> Option<&Backtrace> {
        self.inner.backtrace()
    }
}

impl From<TokenInfoErrorKind> for TokenInfoError {
    fn from(kind: TokenInfoErrorKind) -> TokenInfoError {
        TokenInfoError {
            inner: Context::new(kind),
        }
    }
}

impl From<Context<TokenInfoErrorKind>> for TokenInfoError {
    fn from(inner: Context<TokenInfoErrorKind>) -> TokenInfoError {
        TokenInfoError { inner: inner }
    }
}

impl fmt::Display for TokenInfoError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fmt::Display::fmt(&self.inner, f)
    }
}

#[derive(Debug, Clone, Fail)]
pub enum TokenInfoErrorKind {
    #[fail(display = "{}", _0)]
    InvalidResponseContent(String),
    #[fail(display = "{}", _0)]
    UrlError(String),
    #[fail(display = "{}", _0)]
    NotAuthenticated(String),
    #[fail(display = "{}", _0)]
    Connection(String),
    #[fail(display = "{}", _0)]
    Io(String),
    #[fail(display = "{}", _0)]
    Client(String),
    #[fail(display = "{}", _0)]
    Server(String),
    #[fail(display = "{}", _0)]
    Other(String),
}