mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
handle libmcaptcha actor errors
This commit is contained in:
25
src/data.rs
25
src/data.rs
@@ -41,6 +41,7 @@ use libmcaptcha::{
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::errors::ServiceResult;
|
||||
use crate::SETTINGS;
|
||||
|
||||
/// Represents mCaptcha cache and master system.
|
||||
@@ -80,29 +81,29 @@ impl SystemGroup {
|
||||
}
|
||||
|
||||
/// utility function to AddSite
|
||||
pub async fn add_site(&self, msg: AddSite) -> CaptchaResult<()> {
|
||||
pub async fn add_site(&self, msg: AddSite) -> ServiceResult<()> {
|
||||
match self {
|
||||
Self::Embedded(val) => val.master.send(msg).await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?,
|
||||
};
|
||||
Self::Embedded(val) => val.master.send(msg).await?.await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?.await?,
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// utility function to rename captcha
|
||||
pub async fn rename(&self, msg: Rename) -> CaptchaResult<()> {
|
||||
pub async fn rename(&self, msg: Rename) -> ServiceResult<()> {
|
||||
match self {
|
||||
Self::Embedded(val) => val.master.send(msg).await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?,
|
||||
};
|
||||
Self::Embedded(val) => val.master.send(msg).await?.await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?.await?,
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// utility function to remove captcha
|
||||
pub async fn remove(&self, msg: RemoveCaptcha) -> CaptchaResult<()> {
|
||||
pub async fn remove(&self, msg: RemoveCaptcha) -> ServiceResult<()> {
|
||||
match self {
|
||||
Self::Embedded(val) => val.master.send(msg).await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?,
|
||||
};
|
||||
Self::Embedded(val) => val.master.send(msg).await?.await?,
|
||||
Self::Redis(val) => val.master.send(msg).await?.await?,
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
use std::convert::From;
|
||||
|
||||
use actix::MailboxError;
|
||||
use actix_web::{
|
||||
dev::BaseHttpResponseBuilder as HttpResponseBuilder,
|
||||
error::ResponseError,
|
||||
@@ -28,6 +29,7 @@ use derive_more::{Display, Error};
|
||||
use lettre::transport::smtp::Error as SmtpError;
|
||||
use libmcaptcha::errors::CaptchaError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::oneshot::error::RecvError;
|
||||
use url::ParseError;
|
||||
use validator::ValidationErrors;
|
||||
|
||||
@@ -223,6 +225,24 @@ impl From<SmtpError> for ServiceError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl From<RecvError> for ServiceError {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
fn from(e: RecvError) -> Self {
|
||||
log::error!("{:?}", e);
|
||||
ServiceError::InternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
impl From<MailboxError> for ServiceError {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
fn from(e: MailboxError) -> Self {
|
||||
log::error!("{:?}", e);
|
||||
ServiceError::InternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
pub type ServiceResult<V> = std::result::Result<V, ServiceError>;
|
||||
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
use std::env;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
mod data;
|
||||
mod settings;
|
||||
|
||||
pub use data::Data;
|
||||
pub use settings::Settings;
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
@@ -33,7 +32,11 @@ lazy_static! {
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
#[actix_rt::main]
|
||||
async fn main() {
|
||||
let data = Data::new().await;
|
||||
let db = PgPoolOptions::new()
|
||||
.max_connections(SETTINGS.database.pool)
|
||||
.connect(&SETTINGS.database.url)
|
||||
.await
|
||||
.expect("Unable to form database pool");
|
||||
|
||||
for arg in env::args() {
|
||||
if arg == "--build" {
|
||||
@@ -42,7 +45,7 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
sqlx::migrate!("./migrations/").run(&data.db).await.unwrap();
|
||||
sqlx::migrate!("./migrations/").run(&db).await.unwrap();
|
||||
}
|
||||
|
||||
fn build() {
|
||||
|
||||
Reference in New Issue
Block a user