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
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::error;
#[cfg(feature = "reqwest")]
use reqwest;
use url;

#[derive(Debug)]
pub enum Error {
    #[cfg(feature = "reqwest")]
    NetworkError(reqwest::Error),
    UrlParseError(url::ParseError),
    Unexpected,
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter) -> FmtResult {
        match *self {
            #[cfg(feature = "reqwest")]
            Error::NetworkError(ref e)   => write!(f, "NetworkError:  {}", e),
            Error::UrlParseError(ref e)  => write!(f, "UrlParseError:  {}", e),
            Error::Unexpected            => write!(f, "UnexpectedError"),
        }
    }
}

impl From<url::ParseError> for Error {
    fn from(err: url::ParseError) -> Error {
        Error::UrlParseError(err)
    }
}

#[cfg(feature = "reqwest")]
impl From<reqwest::Error> for Error {
    fn from(err: reqwest::Error) -> Error {
        Error::NetworkError(err)
    }
}

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