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