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
#[derive(Debug)]
pub enum ServerError {
    Hyper(hyper::Error),
    Noise(tokio_noise::NoiseError),
}

impl From<hyper::Error> for ServerError {
    fn from(e: hyper::Error) -> Self {
        ServerError::Hyper(e)
    }
}
impl From<tokio_noise::NoiseError> for ServerError {
    fn from(e: tokio_noise::NoiseError) -> Self {
        ServerError::Noise(e)
    }
}

impl std::fmt::Display for ServerError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        use ServerError::*;
        write!(
            f,
            "noise HTTP server error: {}",
            match self {
                Hyper(e) => format!("hyper error: {e}"),
                Noise(e) => format!("noise error: {e}"),
            }
        )
    }
}

impl std::error::Error for ServerError {}

#[derive(Debug)]
pub enum ClientError {
    Hyper(hyper::Error),
    Noise(tokio_noise::NoiseError),
}

impl From<hyper::Error> for ClientError {
    fn from(e: hyper::Error) -> Self {
        Self::Hyper(e)
    }
}
impl From<tokio_noise::NoiseError> for ClientError {
    fn from(e: tokio_noise::NoiseError) -> Self {
        Self::Noise(e)
    }
}

impl std::fmt::Display for ClientError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        use ClientError::*;
        write!(
            f,
            "noise HTTP client error: {}",
            match self {
                Hyper(e) => format!("hyper error: {e}"),
                Noise(e) => format!("noise error: {e}"),
            }
        )
    }
}

impl std::error::Error for ClientError {}