diff --git a/examples/basics/hello-name/src/main.rs b/examples/basics/hello-name/src/main.rs index 9670965e..6d59d482 100644 --- a/examples/basics/hello-name/src/main.rs +++ b/examples/basics/hello-name/src/main.rs @@ -13,7 +13,7 @@ impl ModuleTrait for HelloName { async fn hello_name( request: service::HttpRequest, path: service::web::Path, -) -> ResultPage { +) -> ResultPage { let name = path.into_inner(); Page::new(request) .with_component_in("content", Html::with(html! { h1 { "Hello " (name) "!" } })) diff --git a/examples/basics/hello-world/src/main.rs b/examples/basics/hello-world/src/main.rs index 50f61973..22ee8bf3 100644 --- a/examples/basics/hello-world/src/main.rs +++ b/examples/basics/hello-world/src/main.rs @@ -9,7 +9,7 @@ impl ModuleTrait for HelloWorld { } } -async fn hello_world(request: service::HttpRequest) -> ResultPage { +async fn hello_world(request: service::HttpRequest) -> ResultPage { Page::new(request) .with_component_in("content", Html::with(html! { h1 { "Hello World!" } })) .render() diff --git a/pagetop-admin/src/summary.rs b/pagetop-admin/src/summary.rs index 497eb630..bc4b19d8 100644 --- a/pagetop-admin/src/summary.rs +++ b/pagetop-admin/src/summary.rs @@ -2,7 +2,7 @@ use crate::LOCALES_ADMIN; use pagetop::prelude::*; -pub async fn summary(request: service::HttpRequest) -> ResultPage { +pub async fn summary(request: service::HttpRequest) -> ResultPage { let top_menu = Menu::new() .with_id("admin-menu-test") .add_item(menu::Item::label(L10n::t("module_name", &LOCALES_ADMIN))) diff --git a/pagetop-homedemo/src/lib.rs b/pagetop-homedemo/src/lib.rs index a54b5732..a8644494 100644 --- a/pagetop-homedemo/src/lib.rs +++ b/pagetop-homedemo/src/lib.rs @@ -22,7 +22,7 @@ impl ModuleTrait for HomeDemo { } } -async fn demo(request: service::HttpRequest) -> ResultPage { +async fn demo(request: service::HttpRequest) -> ResultPage { Page::new(request) .with_title(L10n::t("page_title", &LOCALES_HOMEDEMO)) .with_context(ContextOp::AddStyleSheet(StyleSheet::at( diff --git a/pagetop-node/src/lib.rs b/pagetop-node/src/lib.rs index f994a696..26827674 100644 --- a/pagetop-node/src/lib.rs +++ b/pagetop-node/src/lib.rs @@ -35,7 +35,7 @@ impl ModuleTrait for Node { } } -async fn node(request: service::HttpRequest) -> ResultPage { +async fn node(request: service::HttpRequest) -> ResultPage { Page::new(request).with_title(L10n::n("Nodo")).render() } diff --git a/pagetop-user/src/lib.rs b/pagetop-user/src/lib.rs index 4bc46ec1..7285b873 100644 --- a/pagetop-user/src/lib.rs +++ b/pagetop-user/src/lib.rs @@ -30,7 +30,7 @@ impl ModuleTrait for User { } } -async fn login(request: service::HttpRequest) -> ResultPage { +async fn login(request: service::HttpRequest) -> ResultPage { Page::new(request) .with_title(L10n::n("Identificación del usuario")) .with_component_in( diff --git a/pagetop/src/app.rs b/pagetop/src/app.rs index 8e52a747..d4e4b1ed 100644 --- a/pagetop/src/app.rs +++ b/pagetop/src/app.rs @@ -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 { - Err(FatalError::NotFound(request)) +async fn service_not_found(request: service::HttpRequest) -> ResultPage { + Err(ErrorPage::NotFound(request)) } fn show_banner() { diff --git a/pagetop/src/lib.rs b/pagetop/src/lib.rs index 7fc3d7a7..ecbda884 100644 --- a/pagetop/src/lib.rs +++ b/pagetop/src/lib.rs @@ -53,7 +53,7 @@ //! } //! } //! -//! async fn hello_world(request: service::HttpRequest) -> ResultPage { +//! async fn hello_world(request: service::HttpRequest) -> ResultPage { //! Page::new(request) //! .with_component_in("content", Html::with(html! { h1 { "Hello World!" } })) //! .render() diff --git a/pagetop/src/prelude.rs b/pagetop/src/prelude.rs index 9c2d949c..935de58c 100644 --- a/pagetop/src/prelude.rs +++ b/pagetop/src/prelude.rs @@ -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; diff --git a/pagetop/src/response.rs b/pagetop/src/response.rs index 7878d767..72215229 100644 --- a/pagetop/src/response.rs +++ b/pagetop/src/response.rs @@ -5,5 +5,3 @@ pub use actix_web::ResponseError; pub mod page; pub mod redirect; - -pub mod fatal_error; diff --git a/pagetop/src/response/page.rs b/pagetop/src/response/page.rs index 9b84d3e2..66d7af37 100644 --- a/pagetop/src/response/page.rs +++ b/pagetop/src/response/page.rs @@ -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 { + pub fn render(&mut self) -> ResultPage { // Theme actions before preparing the page body. self.context.theme().before_prepare_body(self); diff --git a/pagetop/src/response/fatal_error.rs b/pagetop/src/response/page/error.rs similarity index 63% rename from pagetop/src/response/fatal_error.rs rename to pagetop/src/response/page/error.rs index 5e572fb9..19d86e57 100644 --- a/pagetop/src/response/fatal_error.rs +++ b/pagetop/src/response/page/error.rs @@ -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, } } }