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
use std::error;
use std::fmt;
use std::fmt::{Display, Formatter};
use hyper;

/// Airwave API client errors
#[derive(Debug)]
pub enum Error {
    /// An authentication error
    Authentication,
    /// An HTTP error from Hyper
    Hyper(hyper::error::Error),
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        match *self {
            Error::Authentication => f.write_str("authentication failed"),
            Error::Hyper(ref e) => Display::fmt(e, f),
        }
    }
}

impl error::Error for Error {
    fn description(&self) -> &str {
        "Aruba client error"
    }

    fn cause(&self) -> Option<&error::Error> {
        match *self {
            Error::Authentication => None,
            Error::Hyper(ref e) => Some(e),
        }
    }
}