levels, duration and tests

This commit is contained in:
realaravinth
2021-03-13 23:50:14 +05:30
parent 096dcd32e4
commit e5ae38472d
10 changed files with 766 additions and 264 deletions

View File

@@ -15,23 +15,22 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::convert::From;
use actix_web::{
dev::HttpResponseBuilder,
error::ResponseError,
http::{header, StatusCode},
HttpResponse,
};
use argon2_creds::errors::CredsError;
use url::ParseError;
use derive_more::{Display, Error};
use log::debug;
use m_captcha::errors::CaptchaError;
use serde::{Deserialize, Serialize};
use url::ParseError;
use validator::ValidationErrors;
use std::convert::From;
#[derive(Debug, Display, Clone, PartialEq, Error)]
#[cfg(not(tarpaulin_include))]
pub enum ServiceError {
@@ -72,13 +71,15 @@ pub enum ServiceError {
/// when the a username is already taken
#[display(fmt = "Username not available")]
UsernameTaken,
/// when the a token name is already taken
#[display(fmt = "token name not available")]
TokenNameTaken,
/// when the a host name is already taken
#[display(fmt = "host name not available")]
HostnameTaken,
#[display(fmt = "{}", _0)]
CaptchaError(CaptchaError),
}
#[derive(Serialize, Deserialize)]
@@ -101,7 +102,7 @@ impl ResponseError for ServiceError {
#[cfg(not(tarpaulin_include))]
fn status_code(&self) -> StatusCode {
println!("{:?}", &self);
match *self {
match self {
ServiceError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
ServiceError::NotAnEmail => StatusCode::BAD_REQUEST,
ServiceError::NotAUrl => StatusCode::BAD_REQUEST,
@@ -116,6 +117,11 @@ impl ResponseError for ServiceError {
ServiceError::UsernameTaken => StatusCode::BAD_REQUEST,
ServiceError::TokenNameTaken => StatusCode::BAD_REQUEST,
ServiceError::HostnameTaken => StatusCode::BAD_REQUEST,
ServiceError::CaptchaError(e) => match e {
CaptchaError::MailboxError => StatusCode::INTERNAL_SERVER_ERROR,
_ => StatusCode::BAD_REQUEST,
},
}
}
}
@@ -148,6 +154,12 @@ impl From<ParseError> for ServiceError {
}
}
impl From<CaptchaError> for ServiceError {
fn from(e: CaptchaError) -> ServiceError {
ServiceError::CaptchaError(e)
}
}
#[cfg(not(tarpaulin_include))]
impl From<sqlx::Error> for ServiceError {
#[cfg(not(tarpaulin_include))]