blob: e4999c8834a1ec42724d3375200d7b9d0b683780 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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())
}
}
|