chore: rm PageError
This commit is contained in:
parent
009ee5d11e
commit
654a898413
1 changed files with 2 additions and 111 deletions
113
src/errors.rs
113
src/errors.rs
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
//use actix::MailboxError;
|
|
||||||
use argon2_creds::errors::CredsError;
|
use argon2_creds::errors::CredsError;
|
||||||
|
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
|
@ -25,11 +24,9 @@ use actix_web::{
|
||||||
HttpResponse, HttpResponseBuilder,
|
HttpResponse, HttpResponseBuilder,
|
||||||
};
|
};
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
//use libmcaptcha::errors::CaptchaError;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
//use tokio::sync::oneshot::error::RecvError;
|
|
||||||
|
|
||||||
#[derive(Debug, Display, PartialEq, Error)]
|
#[derive(Debug, Display, PartialEq, Eq, Error)]
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
pub enum ServiceError {
|
pub enum ServiceError {
|
||||||
#[display(fmt = "internal server error")]
|
#[display(fmt = "internal server error")]
|
||||||
|
@ -40,7 +37,7 @@ pub enum ServiceError {
|
||||||
UsernameTaken,
|
UsernameTaken,
|
||||||
|
|
||||||
#[display(
|
#[display(
|
||||||
fmt = "This server is is closed for registration. Contact admin if this is unexpecter"
|
fmt = "This server is is closed for registration. Contact admin if this is unexpected"
|
||||||
)]
|
)]
|
||||||
ClosedForRegistration,
|
ClosedForRegistration,
|
||||||
|
|
||||||
|
@ -79,8 +76,6 @@ pub enum ServiceError {
|
||||||
PasswordTooLong,
|
PasswordTooLong,
|
||||||
#[display(fmt = "Passwords don't match")]
|
#[display(fmt = "Passwords don't match")]
|
||||||
PasswordsDontMatch,
|
PasswordsDontMatch,
|
||||||
// #[display(fmt = "{}", _0)]
|
|
||||||
// CaptchaError(CaptchaError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -123,24 +118,10 @@ impl ResponseError for ServiceError {
|
||||||
ServiceError::PasswordTooShort => StatusCode::BAD_REQUEST,
|
ServiceError::PasswordTooShort => StatusCode::BAD_REQUEST,
|
||||||
ServiceError::PasswordTooLong => StatusCode::BAD_REQUEST,
|
ServiceError::PasswordTooLong => StatusCode::BAD_REQUEST,
|
||||||
ServiceError::PasswordsDontMatch => StatusCode::BAD_REQUEST,
|
ServiceError::PasswordsDontMatch => StatusCode::BAD_REQUEST,
|
||||||
// ServiceError::CaptchaError(e) => {
|
|
||||||
// log::error!("{}", e);
|
|
||||||
// match e {
|
|
||||||
// CaptchaError::MailboxError => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
// _ => StatusCode::BAD_REQUEST,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[cfg(not(tarpaulin_include))]
|
|
||||||
//impl From<CaptchaError> for ServiceError {
|
|
||||||
// fn from(e: CaptchaError) -> ServiceError {
|
|
||||||
// ServiceError::CaptchaError(e)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
impl From<sqlx::Error> for ServiceError {
|
impl From<sqlx::Error> for ServiceError {
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
|
@ -164,95 +145,5 @@ impl From<CredsError> 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))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
pub type ServiceResult<V> = std::result::Result<V, ServiceError>;
|
pub type ServiceResult<V> = std::result::Result<V, ServiceError>;
|
||||||
|
|
||||||
#[derive(Debug, Display, PartialEq, Error)]
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
pub enum PageError {
|
|
||||||
#[display(fmt = "Something weng wrong: Internal server error")]
|
|
||||||
InternalServerError,
|
|
||||||
|
|
||||||
#[display(fmt = "The page you are looking for doesn't exist")]
|
|
||||||
PageDoesntExist,
|
|
||||||
|
|
||||||
#[display(fmt = "{}", _0)]
|
|
||||||
ServiceError(ServiceError),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
impl From<sqlx::Error> for PageError {
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
fn from(_: sqlx::Error) -> Self {
|
|
||||||
PageError::InternalServerError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
impl From<ServiceError> for PageError {
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
fn from(e: ServiceError) -> Self {
|
|
||||||
PageError::ServiceError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResponseError for PageError {
|
|
||||||
fn error_response(&self) -> HttpResponse {
|
|
||||||
use crate::PAGES;
|
|
||||||
match self.status_code() {
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR => HttpResponse::Found()
|
|
||||||
.append_header((header::LOCATION, PAGES.errors.internal_server_error))
|
|
||||||
.finish(),
|
|
||||||
_ => HttpResponse::Found()
|
|
||||||
.append_header((header::LOCATION, PAGES.errors.unknown_error))
|
|
||||||
.finish(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
fn status_code(&self) -> StatusCode {
|
|
||||||
match self {
|
|
||||||
PageError::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
PageError::PageDoesntExist => StatusCode::NOT_FOUND,
|
|
||||||
PageError::ServiceError(e) => e.status_code(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
|
||||||
pub type PageResult<V> = std::result::Result<V, PageError>;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use crate::PAGES;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn error_works() {
|
|
||||||
let resp: HttpResponse = PageError::InternalServerError.error_response();
|
|
||||||
assert_eq!(resp.status(), StatusCode::FOUND);
|
|
||||||
let headers = resp.headers();
|
|
||||||
assert_eq!(
|
|
||||||
headers.get(header::LOCATION).unwrap(),
|
|
||||||
PAGES.errors.internal_server_error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue