Skip to main content

readability_liveboat/
error.rs

1#[cfg(feature = "reqwest")]
2use reqwest;
3use std::error;
4use std::fmt::{Display, Formatter, Result as FmtResult};
5use std::io;
6use url;
7
8#[derive(Debug)]
9pub enum Error {
10    #[cfg(feature = "reqwest")]
11    NetworkError(reqwest::Error),
12    UrlParseError(url::ParseError),
13    Unexpected,
14    IOError(io::Error),
15    MissingContentType,
16    InvalidContentType(String)
17}
18
19impl Display for Error {
20    fn fmt(&self, f: &mut Formatter) -> FmtResult {
21        match *self {
22            #[cfg(feature = "reqwest")]
23            Error::NetworkError(ref e) => write!(f, "NetworkError:  {}", e),
24            Error::UrlParseError(ref e) => write!(f, "UrlParseError:  {}", e),
25            Error::Unexpected => write!(f, "UnexpectedError"),
26            Error::IOError(ref e) => write!(f, "InputOutputError: {}", e),
27            Error::MissingContentType => write!(f, "No content type returned in response"),
28            Error::InvalidContentType(ref s ) => write!(f, "Received non compatible content type: {}", s),
29        }
30    }
31}
32
33impl From<url::ParseError> for Error {
34    fn from(err: url::ParseError) -> Error {
35        Error::UrlParseError(err)
36    }
37}
38
39impl From<io::Error> for Error {
40    fn from(err: io::Error) -> Error {
41        Error::IOError(err)
42    }
43}
44
45#[cfg(feature = "reqwest")]
46impl From<reqwest::Error> for Error {
47    fn from(err: reqwest::Error) -> Error {
48        Error::NetworkError(err)
49    }
50}
51
52impl error::Error for Error {}