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
//! The crate-wide error type.
use std::fmt;
/// Errors produced by the HTTP engine, the runtimes, and configuration loading.
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
/// The peer sent a malformed request (bad request line, headers, or body
/// framing). Carries a human-readable reason.
BadRequest(&'static str),
/// A request exceeded a configured limit (header bytes, body bytes, …).
TooLarge(&'static str),
/// An I/O error from a socket or the filesystem.
Io(std::io::Error),
/// A TLS-layer error (handshake failure, decrypt error, …). Only produced
/// when the `tls` feature is enabled.
Tls(String),
/// A compression-layer error. Only produced when the `compress` feature is
/// enabled.
Compress(String),
/// A configuration error (invalid TOML, missing file, bad value, …).
Config(String),
/// An ACME certificate-management error (protocol, network, or CA error).
Acme(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::BadRequest(why) => write!(f, "bad request: {why}"),
Error::TooLarge(what) => write!(f, "request too large: {what}"),
Error::Io(e) => write!(f, "io error: {e}"),
Error::Tls(e) => write!(f, "tls error: {e}"),
Error::Compress(e) => write!(f, "compression error: {e}"),
Error::Config(e) => write!(f, "config error: {e}"),
Error::Acme(e) => write!(f, "acme error: {e}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}
/// Convenience alias used throughout the crate.
pub type Result<T> = std::result::Result<T, Error>;