bhttp/
err.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum Error {
5    #[error("a request used the CONNECT method")]
6    ConnectUnsupported,
7    #[error("a field contained invalid Unicode: {0}")]
8    CharacterEncoding(#[from] std::string::FromUtf8Error),
9    #[error("read a response when expecting a request")]
10    ExpectedRequest,
11    #[error("read a request when expecting a response")]
12    ExpectedResponse,
13    #[error("a field contained an integer value that was out of range: {0}")]
14    IntRange(#[from] std::num::TryFromIntError),
15    #[error("the mode of the message was invalid")]
16    InvalidMode,
17    #[error("the status code of a response needs to be in 100..=599")]
18    InvalidStatus,
19    #[error("IO error {0}")]
20    Io(#[from] std::io::Error),
21    #[error("a field or line was missing a necessary character 0x{0:x}")]
22    Missing(u8),
23    #[error("a URL was missing a key component")]
24    MissingUrlComponent,
25    #[error("an obs-fold line was the first line of a field section")]
26    ObsFold,
27    #[error("a field contained a non-integer value: {0}")]
28    ParseInt(#[from] std::num::ParseIntError),
29    #[error("a field was truncated")]
30    Truncated,
31    #[error("a message included the Upgrade field")]
32    UpgradeUnsupported,
33    #[error("a URL could not be parsed into components: {0}")]
34    #[cfg(feature = "read-http")]
35    UrlParse(#[from] url::ParseError),
36}
37
38#[cfg(any(
39    feature = "read-http",
40    feature = "write-http",
41    feature = "read-bhttp",
42    feature = "write-bhttp"
43))]
44pub type Res<T> = Result<T, Error>;