Templates for error messages
This commit is contained in:
parent
4a37a91ece
commit
d9c3bf1191
3 changed files with 23 additions and 4 deletions
25
src/site.rs
25
src/site.rs
|
@ -13,11 +13,19 @@ lazy_static! {
|
|||
|
||||
#[derive(BartDisplay)]
|
||||
#[template = "templates/layout.html"]
|
||||
pub struct Layout<'a, T: 'a + fmt::Display> {
|
||||
struct Layout<'a, T: 'a + fmt::Display> {
|
||||
pub title: &'a str,
|
||||
pub body: &'a T,
|
||||
}
|
||||
|
||||
#[derive(BartDisplay)]
|
||||
#[template = "templates/404.html"]
|
||||
struct NotFound;
|
||||
|
||||
#[derive(BartDisplay)]
|
||||
#[template = "templates/500.html"]
|
||||
struct InternalServerError;
|
||||
|
||||
pub struct Site {
|
||||
state: State
|
||||
}
|
||||
|
@ -43,7 +51,10 @@ impl Service for Site {
|
|||
futures::finished(
|
||||
Response::new()
|
||||
.with_header(ContentType(TEXT_HTML.clone()))
|
||||
.with_body(format!("Page not found"))
|
||||
.with_body(Layout {
|
||||
title: "Not found",
|
||||
body: &NotFound,
|
||||
}.to_string())
|
||||
.with_status(hyper::StatusCode::NotFound)
|
||||
).boxed()
|
||||
} else {
|
||||
|
@ -64,7 +75,10 @@ impl Service for Site {
|
|||
futures::finished(
|
||||
Response::new()
|
||||
.with_header(ContentType(TEXT_HTML.clone()))
|
||||
.with_body(format!("Article not found."))
|
||||
.with_body(Layout {
|
||||
title: "Not found",
|
||||
body: &NotFound,
|
||||
}.to_string())
|
||||
.with_status(hyper::StatusCode::NotFound)
|
||||
).boxed()
|
||||
},
|
||||
|
@ -73,7 +87,10 @@ impl Service for Site {
|
|||
futures::finished(
|
||||
Response::new()
|
||||
.with_header(ContentType(TEXT_HTML.clone()))
|
||||
.with_body(format!("Internal server error"))
|
||||
.with_body(Layout {
|
||||
title: "Internal server error",
|
||||
body: &InternalServerError,
|
||||
}.to_string())
|
||||
.with_status(hyper::StatusCode::InternalServerError)
|
||||
).boxed()
|
||||
}
|
||||
|
|
1
templates/404.html
Normal file
1
templates/404.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p>Not found</p>
|
1
templates/500.html
Normal file
1
templates/500.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p>Internal server error</p>
|
Loading…
Reference in a new issue