1use actix_session::{SessionGetError, SessionInsertError};
4use actix_web::{cookie::time::error::ComponentRange, http::StatusCode, ResponseError};
5use derive_more::derive::{Display, Error, From};
6
7#[derive(Debug, Display, Error, From)]
9#[display("{_0}")]
10pub struct LoginError(SessionInsertError);
11
12impl ResponseError for LoginError {
13 fn status_code(&self) -> StatusCode {
14 StatusCode::UNAUTHORIZED
15 }
16}
17
18#[derive(Debug, Display, Error)]
20#[display("The given session has expired and is no longer valid")]
21pub struct SessionExpiryError(#[error(not(source))] pub(crate) ComponentRange);
22
23#[derive(Debug, Display, Error)]
27#[display(
28 "The identity information in the current session has disappeared after having been \
29 successfully validated. This is likely to be a bug."
30)]
31#[non_exhaustive]
32pub struct LostIdentityError;
33
34#[derive(Debug, Display, Error)]
36#[display("There is no identity information attached to the current session")]
37#[non_exhaustive]
38pub struct MissingIdentityError;
39
40#[derive(Debug, Display, Error, From)]
42#[non_exhaustive]
43pub enum GetIdentityError {
44 #[display("{_0}")]
46 SessionExpiryError(SessionExpiryError),
47
48 #[display("{_0}")]
50 MissingIdentityError(MissingIdentityError),
51
52 #[display("{_0}")]
54 SessionGetError(SessionGetError),
55
56 #[display("{_0}")]
60 LostIdentityError(LostIdentityError),
61}
62
63impl ResponseError for GetIdentityError {
64 fn status_code(&self) -> StatusCode {
65 match self {
66 Self::LostIdentityError(_) => StatusCode::INTERNAL_SERVER_ERROR,
67 _ => StatusCode::UNAUTHORIZED,
68 }
69 }
70}