simple_server/
error.rs

1use http;
2use httparse;
3use std;
4
5/// Various errors that may happen while handling requests.
6#[derive(Debug)]
7pub enum Error {
8    /// An error while doing I/O.
9    Io(std::io::Error),
10    /// An HTTP error.
11    Http(http::Error),
12    /// An error while parsing the HTTP request.
13    HttpParse(httparse::Error),
14    /// An error while parsing the URI of the request.
15    InvalidUri(http::uri::InvalidUri),
16    /// The request timed out.
17    Timeout,
18    #[doc(hidden)]
19    RequestIncomplete,
20    /// The request's size (headers + body) exceeded the application's limit.
21    RequestTooLarge,
22    /// The connection was closed while reading the request.
23    ConnectionClosed,
24}
25
26impl From<std::io::Error> for Error {
27    fn from(err: std::io::Error) -> Error {
28        Error::Io(err)
29    }
30}
31
32impl From<http::Error> for Error {
33    fn from(err: http::Error) -> Error {
34        Error::Http(err)
35    }
36}
37
38impl From<httparse::Error> for Error {
39    fn from(err: httparse::Error) -> Error {
40        Error::HttpParse(err)
41    }
42}
43
44impl From<http::uri::InvalidUri> for Error {
45    fn from(err: http::uri::InvalidUri) -> Error {
46        Error::InvalidUri(err)
47    }
48}