typed_session/error.rs
1use std::fmt::Debug;
2
3/// All errors that can occur in this crate.
4#[derive(Debug, thiserror::Error)]
5#[allow(missing_copy_implementations)]
6pub enum Error<SessionStoreConnectorError> {
7 /// A session was attempted to be updated, but the session does not exist.
8 /// This may happen due to concurrent modification, and is forbidden to prevent data inconsistencies.
9 /// If you receive this error, revert everything that you did while handling the request that
10 /// used this session.
11 #[error("the session that was attempted to be updated does not exist, which indicates that it was concurrently modified or deleted")]
12 UpdatedSessionDoesNotExist,
13
14 /// Tried as often as desired to generate a session id, but all generated ids already exist.
15 #[error("the maximum number of retries to generate a session id was reached")]
16 MaximumSessionIdGenerationTriesReached {
17 /// The maximum number of retries that was reached.
18 maximum: u32,
19 },
20
21 /// The given cookie has a wrong length.
22 #[error("the given cookie has length {actual}, but is expected to have length {expected}")]
23 WrongCookieLength {
24 /// The expected cookie length.
25 expected: usize,
26 /// The actual cookie length.
27 actual: usize,
28 },
29
30 /// An error occurred in the session store connector.
31 #[error("{0}")]
32 SessionStoreConnector(SessionStoreConnectorError),
33}
34
35impl<SessionStoreConnectorError> From<SessionStoreConnectorError>
36 for Error<SessionStoreConnectorError>
37{
38 fn from(error: SessionStoreConnectorError) -> Self {
39 Self::SessionStoreConnector(error)
40 }
41}
42
43/*impl<SessionStoreConnectorError: Display> Display for Error<SessionStoreConnectorError> {
44 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
45 match self {
46 Error::UpdatedSessionDoesNotExist => write!(f, "the updated session does not exist, which indicates that it was concurrently modified or deleted."),
47 Error::MaximumSessionIdGenerationTriesReached => write!(f, "tried to generate a new session id but generated only existing ids until the maximum retry limit was reached."),
48 Error::WrongCookieLength { expected, actual } => write!(f, "wrong cookie length, expected {expected}, but got {actual}"),
49 Error::SessionStoreConnector(error) => write!(f, "{error}"),
50 }
51 }
52}*/
53
54mod expect_impl_error {
55 trait ExpectImplError: std::error::Error {}
56
57 impl<SessionStoreConnectorError: std::error::Error> ExpectImplError
58 for super::Error<SessionStoreConnectorError>
59 {
60 }
61}