cookie_monster/
error.rs

1use std::fmt::Display;
2
3#[derive(Debug, PartialEq, Eq)]
4#[non_exhaustive]
5pub enum Error {
6    // Name - value
7    EqualsNotFound,
8    NameEmpty,
9    InvalidName,
10    InvalidValue,
11
12    // Expires
13    ExpiresFmt,
14
15    // cookie-value
16    PercentDecodeError,
17
18    // Path
19    InvalidPathValue,
20    EmptyPathValue,
21}
22
23impl Display for Error {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        let err = match self {
26            Error::EqualsNotFound => "No '=' found in the cookie",
27            Error::NameEmpty => "The cookie name is empty",
28            Error::InvalidName => "The cookie name contains an invalid character",
29            Error::InvalidValue => "The cookie value contains an invalid value",
30            Error::ExpiresFmt => "Failed to format the expires value",
31            Error::PercentDecodeError => "An error occured while decoding",
32            Error::InvalidPathValue => "The path attribute contains an invalid value",
33            Error::EmptyPathValue => "The path attribute is empty",
34        };
35
36        f.write_str(err)
37    }
38}
39
40impl std::error::Error for Error {}