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
use reqwest::Error as HttpError;
use std::{
    fmt::{self, Display},
    io::Error as IoError,
};
use trust_dns_proto::error::ProtoError;

#[derive(Debug)]
pub enum UpstreamError {
    Io(IoError),
    Proto(ProtoError),
    Http(HttpError),
}

impl Display for UpstreamError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            UpstreamError::Io(ref cause) => {
                write!(f, "[upstream] {}", cause)
            }
            UpstreamError::Proto(ref cause) => {
                write!(f, "[upstream] {}", cause)
            }
            UpstreamError::Http(ref cause) => {
                write!(f, "[upstream] {}", cause)
            }
        }
    }
}

impl From<IoError> for UpstreamError {
    fn from(cause: IoError) -> UpstreamError {
        UpstreamError::Io(cause)
    }
}

impl From<ProtoError> for UpstreamError {
    fn from(cause: ProtoError) -> UpstreamError {
        UpstreamError::Proto(cause)
    }
}

impl From<HttpError> for UpstreamError {
    fn from(cause: HttpError) -> UpstreamError {
        UpstreamError::Http(cause)
    }
}