Añade el error 404 integrado en el servidor web
This commit is contained in:
parent
1543ab2960
commit
1363c3da1f
3 changed files with 51 additions and 34 deletions
|
|
@ -1,6 +1,8 @@
|
|||
use super::AppTrait;
|
||||
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::{base, trace, Lazy};
|
||||
|
||||
use actix_web::dev::Server;
|
||||
|
|
@ -57,6 +59,7 @@ impl Application {
|
|||
.wrap(tracing_actix_web::TracingLogger::default())
|
||||
.configure(&module::all::modules)
|
||||
.configure(&theme::all::themes)
|
||||
.default_service(super::web::route().to(service_not_found))
|
||||
})
|
||||
.bind(format!(
|
||||
"{}:{}",
|
||||
|
|
@ -71,3 +74,23 @@ impl Application {
|
|||
Ok(self.server)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,35 +34,22 @@ impl ThemeTrait for Bootsier {
|
|||
.alter_context(InContextOp::AddJQuery);
|
||||
}
|
||||
|
||||
fn render_error_page(&self, mut s: app::http::StatusCode) -> ResultPage<Markup, FatalError> {
|
||||
let mut description = "e500-description";
|
||||
let mut message = "e500-description";
|
||||
match s {
|
||||
app::http::StatusCode::NOT_FOUND => {
|
||||
description = "e404-description";
|
||||
message = "e404-message";
|
||||
}
|
||||
_ => {
|
||||
s = app::http::StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
}
|
||||
Page::new()
|
||||
.with_title(format!("Error {}", s.as_str()).as_str())
|
||||
.add_to(
|
||||
"content",
|
||||
fn error_404_not_found(&self) -> Container {
|
||||
Container::new()
|
||||
.with_component(
|
||||
Chunck::with(html! {
|
||||
div class="jumbotron" {
|
||||
div class="media" {
|
||||
img
|
||||
src="/static/bootsier/images/caution.png"
|
||||
src="/bootsier/images/caution.png"
|
||||
class="mr-4"
|
||||
style="width: 20%; max-width: 188px"
|
||||
alt="Caution!";
|
||||
div class="media-body" {
|
||||
h1 class="display-4" { (s.as_str()) }
|
||||
p class="lead" { (l(description)) }
|
||||
h1 class="display-4" { ("RESOURCE NOT FOUND") }
|
||||
p class="lead" { (l("e404-description")) }
|
||||
hr class="my-4";
|
||||
p { (l(message)) }
|
||||
p { (l("e404-description")) }
|
||||
a
|
||||
class="btn btn-primary btn-lg"
|
||||
href="/"
|
||||
|
|
@ -73,8 +60,7 @@ impl ThemeTrait for Bootsier {
|
|||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
})
|
||||
)
|
||||
.render()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use crate::base::component::Chunck;
|
||||
use crate::app;
|
||||
use crate::base::component::{Chunck, Container};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::core::component::{ComponentTrait, InContext, InContextOp};
|
||||
use crate::html::{html, Favicon, Markup};
|
||||
use crate::response::page::Page;
|
||||
use crate::{concat_string, util};
|
||||
use crate::{app, app::fatal_error::FatalError};
|
||||
use crate::response::page::{Page, ResultPage};
|
||||
|
||||
pub trait BaseTheme {
|
||||
fn single_name(&self) -> &'static str;
|
||||
|
|
@ -117,18 +117,26 @@ pub trait ThemeTrait: BaseTheme + Send + Sync {
|
|||
*/
|
||||
}
|
||||
|
||||
fn render_error_page(&self, s: app::http::StatusCode) -> ResultPage<Markup, FatalError> {
|
||||
Page::new()
|
||||
.with_title(format!("Error {}", s.as_str()).as_str())
|
||||
.add_to(
|
||||
"content",
|
||||
fn error_404_not_found(&self) -> Container {
|
||||
Container::new()
|
||||
.with_component(
|
||||
Chunck::with(html! {
|
||||
div {
|
||||
h1 { (s.as_str()) }
|
||||
h1 { ("RESOURCE NOT FOUND") }
|
||||
}
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fn error_403_access_denied(&self) -> Container {
|
||||
Container::new()
|
||||
.with_component(
|
||||
Chunck::with(html! {
|
||||
div {
|
||||
h1 { ("FORBIDDEN ACCESS") }
|
||||
}
|
||||
})
|
||||
)
|
||||
.render()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue