use actix_session::{SessionGetError, SessionInsertError}; use actix_web::{body::BoxBody, HttpResponse, ResponseError}; #[derive(Debug)] pub enum PinussyError { Database(sqlx::Error), SessionInsertError, SessionGetError, Bcrypt, } impl From for PinussyError { fn from(_: SessionInsertError) -> Self { Self::SessionInsertError } } impl From for PinussyError { fn from(_: SessionGetError) -> Self { Self::SessionGetError } } impl From for PinussyError { fn from(e: sqlx::Error) -> Self { Self::Database(e) } } impl From for PinussyError { fn from(_: bcrypt::BcryptError) -> Self { Self::Bcrypt } } impl std::fmt::Display for PinussyError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self) } } impl std::error::Error for PinussyError {} impl ResponseError for PinussyError { fn error_response(&self) -> HttpResponse { HttpResponse::new(self.status_code()) } }