webdav_request/
error.rs

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use reqwest::StatusCode;

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

pub enum Error {
    StdError(std::io::Error),
    RequestError(reqwest::Error),
    DeError(quick_xml::DeError),
    ResponseError(StatusCode),
    Utf8Error(std::str::Utf8Error)
}

impl Error {
    pub fn is_std_err(&self) -> bool {
        match self {
            Self::StdError(_) => true,
            _ => false
        }
    }

    pub fn is_request_err(&self) -> bool {
        match self {
            Self::RequestError(_) => true,
            _ => false
        }
    }
    pub fn is_de_err(&self) -> bool {
        match self {
            Self::DeError(_) => true,
            _ => false
        }
    }
    pub fn is_response_err(&self) -> bool {
        match self {
            Self::ResponseError(_) => true,
            _ => false
        }
    }

    pub fn is_invalid_utf8_err(&self) -> bool {
        match self {
            Self::Utf8Error(_) => true,
            _ => false
        }
    }
}

impl From<std::io::Error> for Error {
    fn from(value: std::io::Error) -> Self {
        Self::StdError(value)
    }
}
impl From<reqwest::Error> for Error {
    fn from(value: reqwest::Error) -> Self {
        Self::RequestError(value)
    }
}
impl From<quick_xml::DeError> for Error {
    fn from(value: quick_xml::DeError) -> Self {
        Self::DeError(value)
    }
}
impl From<std::str::Utf8Error> for Error {
    fn from(value: std::str::Utf8Error) -> Self {
        Self::Utf8Error(value)
    }
}

impl std::fmt::Debug for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::StdError(arg0) => arg0.fmt(f),
            Self::RequestError(arg0) =>arg0.fmt(f),
            Self::DeError(arg0) => arg0.fmt(f),
            Self::ResponseError(arg) => arg.fmt(f),
            Error::Utf8Error(arg) => arg.fmt(f),
        }
    }
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::StdError(arg0) => arg0.fmt(f),
            Self::RequestError(arg0) =>arg0.fmt(f),
            Self::DeError(arg0) => arg0.fmt(f),
            Self::ResponseError(arg) => arg.fmt(f),
            Self::Utf8Error(arg) => arg.fmt(f)
        }
    }
}
impl std::error::Error for Error {
    
}