Provide a 404 page

This commit is contained in:
Konrad Borowski 2019-04-08 10:31:13 +02:00
parent 96e2a362fa
commit 1d998ed2f4
2 changed files with 12 additions and 1 deletions

View File

@ -124,6 +124,10 @@ struct QueryPaste {
no_follow: bool,
}
#[derive(Template)]
#[template(path = "404.html")]
struct PasteNotFound;
impl QueryPaste {
fn into_paste(self) -> Paste {
let QueryPaste {
@ -175,7 +179,9 @@ fn display_paste(
})
.map_err(|e| InternalError::new(e, StatusCode::INTERNAL_SERVER_ERROR).into())
.and_then(|(db, paste)| match paste {
None => Either::A(future::ok(HttpResponse::NotFound().finish())),
None => Either::A(future::ok(
HttpResponse::NotFound().body(PasteNotFound.render().unwrap()),
)),
Some(paste) => Either::B(fetch_languages(&db).and_then(|languages| {
DisplayPaste {
languages,

5
templates/404.html Normal file
View File

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
<h1>Paste not found</h1>
<p>It may have been automatically deleted after 24 hours.
{% endblock content %}