mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-31 05:33:28 +03:00
feat: convert db errors to service errors
This commit is contained in:
parent
f337721b25
commit
43aac949e3
1 changed files with 22 additions and 0 deletions
|
@ -24,6 +24,7 @@ use actix_web::{
|
||||||
HttpResponse, HttpResponseBuilder,
|
HttpResponse, HttpResponseBuilder,
|
||||||
};
|
};
|
||||||
use argon2_creds::errors::CredsError;
|
use argon2_creds::errors::CredsError;
|
||||||
|
use db_core::errors::DBError;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use lettre::transport::smtp::Error as SmtpError;
|
use lettre::transport::smtp::Error as SmtpError;
|
||||||
use libmcaptcha::errors::CaptchaError;
|
use libmcaptcha::errors::CaptchaError;
|
||||||
|
@ -35,6 +36,15 @@ use validator::ValidationErrors;
|
||||||
#[derive(Debug, Display, Error)]
|
#[derive(Debug, Display, Error)]
|
||||||
pub struct SmtpErrorWrapper(SmtpError);
|
pub struct SmtpErrorWrapper(SmtpError);
|
||||||
|
|
||||||
|
#[derive(Debug, Display, Error)]
|
||||||
|
pub struct DBErrorWrapper(DBError);
|
||||||
|
|
||||||
|
impl std::cmp::PartialEq for DBErrorWrapper {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
format!("{}", self.0) == format!("{}", other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl std::cmp::PartialEq for SmtpErrorWrapper {
|
impl std::cmp::PartialEq for SmtpErrorWrapper {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.0.status() == other.0.status()
|
self.0.status() == other.0.status()
|
||||||
|
@ -103,6 +113,9 @@ pub enum ServiceError {
|
||||||
|
|
||||||
#[display(fmt = "{}", _0)]
|
#[display(fmt = "{}", _0)]
|
||||||
CaptchaError(CaptchaError),
|
CaptchaError(CaptchaError),
|
||||||
|
|
||||||
|
#[display(fmt = "{}", _0)]
|
||||||
|
DBError(DBErrorWrapper),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -160,6 +173,8 @@ impl ResponseError for ServiceError {
|
||||||
log::error!("{}", e.0);
|
log::error!("{}", e.0);
|
||||||
StatusCode::INTERNAL_SERVER_ERROR
|
StatusCode::INTERNAL_SERVER_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServiceError::DBError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,6 +194,13 @@ impl From<CredsError> for ServiceError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<DBError> for ServiceError {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
|
fn from(e: DBError) -> ServiceError {
|
||||||
|
ServiceError::DBError(DBErrorWrapper(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<ValidationErrors> for ServiceError {
|
impl From<ValidationErrors> for ServiceError {
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn from(_: ValidationErrors) -> ServiceError {
|
fn from(_: ValidationErrors) -> ServiceError {
|
||||||
|
|
Loading…
Add table
Reference in a new issue