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
59
60
61
62
63
64
65
66
67
68
69
70
use actix_session::{SessionGetError, SessionInsertError};
use actix_web::{cookie::time::error::ComponentRange, http::StatusCode, ResponseError};
use derive_more::{Display, Error, From};
#[derive(Debug, Display, Error, From)]
#[display(fmt = "{_0}")]
pub struct LoginError(SessionInsertError);
impl ResponseError for LoginError {
fn status_code(&self) -> StatusCode {
StatusCode::UNAUTHORIZED
}
}
#[derive(Debug, Display, Error)]
#[display(fmt = "The given session has expired and is no longer valid")]
pub struct SessionExpiryError(#[error(not(source))] pub(crate) ComponentRange);
#[derive(Debug, Display, Error)]
#[display(
fmt = "The identity information in the current session has disappeared after having been \
successfully validated. This is likely to be a bug."
)]
#[non_exhaustive]
pub struct LostIdentityError;
#[derive(Debug, Display, Error)]
#[display(fmt = "There is no identity information attached to the current session")]
#[non_exhaustive]
pub struct MissingIdentityError;
#[derive(Debug, Display, Error, From)]
#[non_exhaustive]
pub enum GetIdentityError {
#[display(fmt = "{_0}")]
SessionExpiryError(SessionExpiryError),
#[display(fmt = "{_0}")]
MissingIdentityError(MissingIdentityError),
#[display(fmt = "{_0}")]
SessionGetError(SessionGetError),
#[display(fmt = "{_0}")]
LostIdentityError(LostIdentityError),
}
impl ResponseError for GetIdentityError {
fn status_code(&self) -> StatusCode {
match self {
Self::LostIdentityError(_) => StatusCode::INTERNAL_SERVER_ERROR,
_ => StatusCode::UNAUTHORIZED,
}
}
}