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
use webdav::response::PropfindParseError;
use hyper;
use std;
use std::error::Error as StdError;

#[derive(Debug)]
pub enum Error {
    Http(hyper::Error),
    PropfindParse(PropfindParseError),
    ErrorResponse(hyper::client::response::Response),
}

impl From<hyper::Error> for Error {
    fn from(e: hyper::Error) -> Self {
        Error::Http(e)
    }
}

impl From<PropfindParseError> for Error {
    fn from(e: PropfindParseError) -> Self {
        Error::PropfindParse(e)
    }
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.description())
    }
}

impl StdError for Error {
    fn description(&self) -> &str {
        use self::Error::*;
        match *self {
            Http(ref e) => e.description(),
            PropfindParse(ref e) => e.description(),
            ErrorResponse(_) => "server returned an error status code",
        }
    }

    fn cause(&self) -> Option<&StdError> {
        use self::Error::*;
        match *self {
            Http(ref e) => Some(e as &StdError),
            PropfindParse(ref e) => Some(e as &StdError),
            _ => None,
        }
    }
}