🚚 Better name for response page errors
This commit is contained in:
parent
68ed0f78b9
commit
09cb6bd7fa
12 changed files with 36 additions and 36 deletions
|
|
@ -13,7 +13,7 @@ impl ModuleTrait for HelloName {
|
|||
async fn hello_name(
|
||||
request: service::HttpRequest,
|
||||
path: service::web::Path<String>,
|
||||
) -> ResultPage<Markup, FatalError> {
|
||||
) -> ResultPage<Markup, ErrorPage> {
|
||||
let name = path.into_inner();
|
||||
Page::new(request)
|
||||
.with_component_in("content", Html::with(html! { h1 { "Hello " (name) "!" } }))
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ impl ModuleTrait for HelloWorld {
|
|||
}
|
||||
}
|
||||
|
||||
async fn hello_world(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
async fn hello_world(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Page::new(request)
|
||||
.with_component_in("content", Html::with(html! { h1 { "Hello World!" } }))
|
||||
.render()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::LOCALES_ADMIN;
|
|||
|
||||
use pagetop::prelude::*;
|
||||
|
||||
pub async fn summary(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
pub async fn summary(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
let top_menu = Menu::new()
|
||||
.with_id("admin-menu-test")
|
||||
.add_item(menu::Item::label(L10n::t("module_name", &LOCALES_ADMIN)))
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ impl ModuleTrait for HomeDemo {
|
|||
}
|
||||
}
|
||||
|
||||
async fn demo(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
async fn demo(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Page::new(request)
|
||||
.with_title(L10n::t("page_title", &LOCALES_HOMEDEMO))
|
||||
.with_context(ContextOp::AddStyleSheet(StyleSheet::at(
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ impl ModuleTrait for Node {
|
|||
}
|
||||
}
|
||||
|
||||
async fn node(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
async fn node(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Page::new(request).with_title(L10n::n("Nodo")).render()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl ModuleTrait for User {
|
|||
}
|
||||
}
|
||||
|
||||
async fn login(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
async fn login(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Page::new(request)
|
||||
.with_title(L10n::n("Identificación del usuario"))
|
||||
.with_component_in(
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ mod figfont;
|
|||
|
||||
use crate::core::{module, module::ModuleRef};
|
||||
use crate::html::Markup;
|
||||
use crate::response::fatal_error::FatalError;
|
||||
use crate::response::page::ResultPage;
|
||||
use crate::response::page::{ErrorPage, ResultPage};
|
||||
use crate::{concat_string, config, locale, service, trace, LazyStatic};
|
||||
|
||||
#[cfg(feature = "database")]
|
||||
|
|
@ -112,8 +111,8 @@ fn service_app() -> service::App<
|
|||
.default_service(service::web::route().to(service_not_found))
|
||||
}
|
||||
|
||||
async fn service_not_found(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
Err(FatalError::NotFound(request))
|
||||
async fn service_not_found(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Err(ErrorPage::NotFound(request))
|
||||
}
|
||||
|
||||
fn show_banner() {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! async fn hello_world(request: service::HttpRequest) -> ResultPage<Markup, FatalError> {
|
||||
//! async fn hello_world(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
//! Page::new(request)
|
||||
//! .with_component_in("content", Html::with(html! { h1 { "Hello World!" } }))
|
||||
//! .render()
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ pub use crate::core::component::*;
|
|||
pub use crate::core::module::*;
|
||||
pub use crate::core::theme::*;
|
||||
|
||||
pub use crate::response::fatal_error::*;
|
||||
pub use crate::response::{page::*, redirect::*, ResponseError};
|
||||
|
||||
pub use crate::base::action;
|
||||
|
|
|
|||
|
|
@ -5,5 +5,3 @@ pub use actix_web::ResponseError;
|
|||
pub mod page;
|
||||
|
||||
pub mod redirect;
|
||||
|
||||
pub mod fatal_error;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
mod error;
|
||||
pub use error::ErrorPage;
|
||||
|
||||
pub use actix_web::Result as ResultPage;
|
||||
|
||||
use crate::base::action;
|
||||
use crate::core::component::{AnyComponents, ArcAnyComponent, ComponentTrait};
|
||||
use crate::core::component::{Context, ContextOp};
|
||||
|
|
@ -5,13 +10,10 @@ use crate::core::theme::ComponentsRegions;
|
|||
use crate::html::{html, Markup, DOCTYPE};
|
||||
use crate::html::{ClassesOp, Favicon, OptionClasses, OptionId, OptionTranslated};
|
||||
use crate::locale::L10n;
|
||||
use crate::response::fatal_error::FatalError;
|
||||
use crate::{fn_builder, service};
|
||||
|
||||
use unic_langid::CharacterDirection;
|
||||
|
||||
pub use actix_web::Result as ResultPage;
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub struct Page {
|
||||
title : OptionTranslated,
|
||||
|
|
@ -154,7 +156,7 @@ impl Page {
|
|||
|
||||
// Page RENDER.
|
||||
|
||||
pub fn render(&mut self) -> ResultPage<Markup, FatalError> {
|
||||
pub fn render(&mut self) -> ResultPage<Markup, ErrorPage> {
|
||||
// Theme actions before preparing the page body.
|
||||
self.context.theme().before_prepare_body(self);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
use crate::base::component::{Error403, Error404};
|
||||
use crate::locale::L10n;
|
||||
use crate::response::{page::Page, ResponseError};
|
||||
use crate::response::ResponseError;
|
||||
use crate::service::http::{header::ContentType, StatusCode};
|
||||
use crate::service::{HttpRequest, HttpResponse};
|
||||
|
||||
use super::Page;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FatalError {
|
||||
pub enum ErrorPage {
|
||||
NotModified(HttpRequest),
|
||||
BadRequest(HttpRequest),
|
||||
AccessDenied(HttpRequest),
|
||||
|
|
@ -17,15 +19,15 @@ pub enum FatalError {
|
|||
Timeout(HttpRequest),
|
||||
}
|
||||
|
||||
impl fmt::Display for FatalError {
|
||||
impl fmt::Display for ErrorPage {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
// Error 304.
|
||||
FatalError::NotModified(_) => write!(f, "Not Modified"),
|
||||
ErrorPage::NotModified(_) => write!(f, "Not Modified"),
|
||||
// Error 400.
|
||||
FatalError::BadRequest(_) => write!(f, "Bad Client Data"),
|
||||
ErrorPage::BadRequest(_) => write!(f, "Bad Client Data"),
|
||||
// Error 403.
|
||||
FatalError::AccessDenied(request) => {
|
||||
ErrorPage::AccessDenied(request) => {
|
||||
let error_page = Page::new(request.clone());
|
||||
if let Ok(page) = error_page
|
||||
.with_title(L10n::n("Error FORBIDDEN"))
|
||||
|
|
@ -39,7 +41,7 @@ impl fmt::Display for FatalError {
|
|||
}
|
||||
}
|
||||
// Error 404.
|
||||
FatalError::NotFound(request) => {
|
||||
ErrorPage::NotFound(request) => {
|
||||
let error_page = Page::new(request.clone());
|
||||
if let Ok(page) = error_page
|
||||
.with_title(L10n::n("Error RESOURCE NOT FOUND"))
|
||||
|
|
@ -53,16 +55,16 @@ impl fmt::Display for FatalError {
|
|||
}
|
||||
}
|
||||
// Error 412.
|
||||
FatalError::PreconditionFailed(_) => write!(f, "Precondition Failed"),
|
||||
ErrorPage::PreconditionFailed(_) => write!(f, "Precondition Failed"),
|
||||
// Error 500.
|
||||
FatalError::InternalError(_) => write!(f, "Internal Error"),
|
||||
ErrorPage::InternalError(_) => write!(f, "Internal Error"),
|
||||
// Error 504.
|
||||
FatalError::Timeout(_) => write!(f, "Timeout"),
|
||||
ErrorPage::Timeout(_) => write!(f, "Timeout"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ResponseError for FatalError {
|
||||
impl ResponseError for ErrorPage {
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::build(self.status_code())
|
||||
.insert_header(ContentType::html())
|
||||
|
|
@ -72,13 +74,13 @@ impl ResponseError for FatalError {
|
|||
#[rustfmt::skip]
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
FatalError::NotModified(_) => StatusCode::NOT_MODIFIED,
|
||||
FatalError::BadRequest(_) => StatusCode::BAD_REQUEST,
|
||||
FatalError::AccessDenied(_) => StatusCode::FORBIDDEN,
|
||||
FatalError::NotFound(_) => StatusCode::NOT_FOUND,
|
||||
FatalError::PreconditionFailed(_) => StatusCode::PRECONDITION_FAILED,
|
||||
FatalError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
FatalError::Timeout(_) => StatusCode::GATEWAY_TIMEOUT,
|
||||
ErrorPage::NotModified(_) => StatusCode::NOT_MODIFIED,
|
||||
ErrorPage::BadRequest(_) => StatusCode::BAD_REQUEST,
|
||||
ErrorPage::AccessDenied(_) => StatusCode::FORBIDDEN,
|
||||
ErrorPage::NotFound(_) => StatusCode::NOT_FOUND,
|
||||
ErrorPage::PreconditionFailed(_) => StatusCode::PRECONDITION_FAILED,
|
||||
ErrorPage::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
ErrorPage::Timeout(_) => StatusCode::GATEWAY_TIMEOUT,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue