mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-12-19 16:46:37 +00:00
Add generic error catchers
This commit is contained in:
parent
bb682a1cc1
commit
58cc35691d
5 changed files with 32 additions and 0 deletions
|
@ -263,3 +263,9 @@ msgstr ""
|
|||
|
||||
msgid "{{ data }} commented your article"
|
||||
msgstr ""
|
||||
|
||||
msgid "We couldn't find this page."
|
||||
msgstr ""
|
||||
|
||||
msgid "The link that led you here may be broken."
|
||||
msgstr ""
|
||||
|
|
|
@ -128,6 +128,10 @@ fn main() {
|
|||
routes::well_known::nodeinfo,
|
||||
routes::well_known::webfinger
|
||||
])
|
||||
.catch(catchers![
|
||||
routes::errors::not_found,
|
||||
routes::errors::server_error
|
||||
])
|
||||
.manage(init_pool())
|
||||
.attach(Template::custom(|engines| {
|
||||
rocket_i18n::tera(&mut engines.tera);
|
||||
|
|
15
src/routes/errors.rs
Normal file
15
src/routes/errors.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use rocket_contrib::Template;
|
||||
|
||||
#[catch(404)]
|
||||
fn not_found() -> Template {
|
||||
Template::render("errors/404", json!({
|
||||
"error_message": "Page not found"
|
||||
}))
|
||||
}
|
||||
|
||||
#[catch(500)]
|
||||
fn server_error() -> Template {
|
||||
Template::render("errors/500", json!({
|
||||
"error_message": "Server error"
|
||||
}))
|
||||
}
|
|
@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
pub mod blogs;
|
||||
pub mod comments;
|
||||
pub mod errors;
|
||||
pub mod instance;
|
||||
pub mod likes;
|
||||
pub mod notifications;
|
||||
|
|
6
templates/errors/404.html.tera
Normal file
6
templates/errors/404.html.tera
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% extends "errors/base" %}
|
||||
|
||||
{% block error %}
|
||||
<h1>{{ "We couldn't find this page." | _ }}</h1>
|
||||
<h2>{{ "The link that led you here may be broken." | _ }}</h2>
|
||||
{% endblock error %}
|
Loading…
Reference in a new issue