Corrige localización errores NOT_FOUND y FORBIDDEN
This commit is contained in:
parent
aa3f0cf79a
commit
bd5ccdef8a
2 changed files with 35 additions and 19 deletions
|
|
@ -2,7 +2,7 @@ use super::{fatal_error::FatalError, AppTrait};
|
|||
use crate::config::SETTINGS;
|
||||
use crate::core::{module, theme};
|
||||
use crate::html::Markup;
|
||||
use crate::response::page::{Page, ResultPage};
|
||||
use crate::response::page::ResultPage;
|
||||
use crate::{base, trace, Lazy};
|
||||
|
||||
use actix_web::dev::Server;
|
||||
|
|
@ -76,21 +76,5 @@ impl Application {
|
|||
}
|
||||
|
||||
async fn service_not_found() -> ResultPage<Markup, FatalError> {
|
||||
let mut page = Page::new();
|
||||
let content_error = page.context().theme().error_404_not_found();
|
||||
page
|
||||
.with_title("Error RESOURCE NOT FOUND")
|
||||
.using_template("error")
|
||||
.add_to("content", content_error)
|
||||
.render()
|
||||
}
|
||||
|
||||
async fn _access_denied() -> ResultPage<Markup, FatalError> {
|
||||
let mut page = Page::new();
|
||||
let content_error = page.context().theme().error_403_access_denied();
|
||||
page
|
||||
.with_title("Error FORBIDDEN ACCESS")
|
||||
.using_template("error")
|
||||
.add_to("content", content_error)
|
||||
.render()
|
||||
Err(FatalError::NotFound)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
use crate::app::HttpResponse;
|
||||
use crate::app::http::{header::ContentType, StatusCode};
|
||||
use crate::response::ResponseError;
|
||||
use crate::response::{page::Page, ResponseError};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FatalError {
|
||||
NotFound,
|
||||
AccessDenied,
|
||||
InternalError,
|
||||
BadClientData,
|
||||
Timeout,
|
||||
|
|
@ -14,6 +16,34 @@ pub enum FatalError {
|
|||
impl fmt::Display for FatalError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
FatalError::NotFound => {
|
||||
let mut error_page = Page::new();
|
||||
let error_content = error_page.context().theme().error_404_not_found();
|
||||
if let Ok(page) = error_page
|
||||
.with_title("Error RESOURCE NOT FOUND")
|
||||
.using_template("error")
|
||||
.add_to("content", error_content)
|
||||
.render()
|
||||
{
|
||||
write!(f, "{}", page.into_string())
|
||||
} else {
|
||||
write!(f, "Not Found")
|
||||
}
|
||||
},
|
||||
FatalError::AccessDenied => {
|
||||
let mut error_page = Page::new();
|
||||
let error_content = error_page.context().theme().error_403_access_denied();
|
||||
if let Ok(page) = error_page
|
||||
.with_title("Error FORBIDDEN")
|
||||
.using_template("error")
|
||||
.add_to("content", error_content)
|
||||
.render()
|
||||
{
|
||||
write!(f, "{}", page.into_string())
|
||||
} else {
|
||||
write!(f, "Access Denied")
|
||||
}
|
||||
},
|
||||
FatalError::InternalError => write!(f, "Internal Error"),
|
||||
FatalError::BadClientData => write!(f, "Bad Client Data"),
|
||||
FatalError::Timeout => write!(f, "Timeout"),
|
||||
|
|
@ -30,6 +60,8 @@ impl ResponseError for FatalError {
|
|||
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match *self {
|
||||
FatalError::NotFound => StatusCode::NOT_FOUND,
|
||||
FatalError::AccessDenied => StatusCode::FORBIDDEN,
|
||||
FatalError::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
FatalError::BadClientData => StatusCode::BAD_REQUEST,
|
||||
FatalError::Timeout => StatusCode::GATEWAY_TIMEOUT,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue