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
use http;
use httparse;
use std;

/// Various errors that may happen while handling requests.
#[derive(Debug)]
pub enum Error {
    /// An error while doing I/O.
    Io(std::io::Error),
    /// An HTTP error.
    Http(http::Error),
    /// An error while parsing the HTTP request.
    HttpParse(httparse::Error),
    /// An error while parsing the URI of the request.
    InvalidUri(http::uri::InvalidUri),
    /// The request timed out.
    Timeout,
    #[doc(hidden)]
    RequestIncomplete,
    /// The request's size (headers + body) exceeded the application's limit.
    RequestTooLarge,
    /// The connection was closed while reading the request.
    ConnectionClosed,
}

impl From<std::io::Error> for Error {
    fn from(err: std::io::Error) -> Error {
        Error::Io(err)
    }
}

impl From<http::Error> for Error {
    fn from(err: http::Error) -> Error {
        Error::Http(err)
    }
}

impl From<httparse::Error> for Error {
    fn from(err: httparse::Error) -> Error {
        Error::HttpParse(err)
    }
}

impl From<http::uri::InvalidUri> for Error {
    fn from(err: http::uri::InvalidUri) -> Error {
        Error::InvalidUri(err)
    }
}