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)]
42#[display("Expected user id to be a String, but found {_0}")]
43pub struct InvalidIdTypeError(#[error(not(source))] pub &'static str);
44
45#[derive(Debug, Display, Error, From)]
47#[non_exhaustive]
48pub enum GetIdentityError {
49 #[display("{_0}")]
51 SessionExpiryError(SessionExpiryError),
52
53 #[display("{_0}")]
55 MissingIdentityError(MissingIdentityError),
56
57 #[display("{_0}")]
59 SessionGetError(SessionGetError),
60
61 #[display("{_0}")]
65 LostIdentityError(LostIdentityError),
66
67 #[display("{_0}")]
69 InvalidIdTypeError(InvalidIdTypeError),
70}
71
72impl ResponseError for GetIdentityError {
73 fn status_code(&self) -> StatusCode {
74 match self {
75 Self::LostIdentityError(_) => StatusCode::INTERNAL_SERVER_ERROR,
76 _ => StatusCode::UNAUTHORIZED,
77 }
78 }
79}