diff options
author | cel 🌸 <cel@blos.sm> | 2023-12-12 14:14:30 +0000 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-12-12 14:14:30 +0000 |
commit | 370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0 (patch) | |
tree | 665163bc58c8e94320b843b1983376d9a67f99bf /src/error.rs | |
parent | 5dc4774ed3380762b4d7aadc86193af6073c456a (diff) | |
download | pinussy-370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0.tar.gz pinussy-370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0.tar.bz2 pinussy-370a25e5a0cbb95e2aa1cec55305b22aeaf99aa0.zip |
initial refactor
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..e4999c8 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,48 @@ +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<SessionInsertError> for PinussyError { + fn from(_: SessionInsertError) -> Self { + Self::SessionInsertError + } +} + +impl From<SessionGetError> for PinussyError { + fn from(_: SessionGetError) -> Self { + Self::SessionGetError + } +} + +impl From<sqlx::Error> for PinussyError { + fn from(e: sqlx::Error) -> Self { + Self::Database(e) + } +} + +impl From<bcrypt::BcryptError> 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<BoxBody> { + HttpResponse::new(self.status_code()) + } +} |