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,
}
}
}