diff --git a/po/plume.pot b/po/plume.pot index 1d36fc36..6eaebfb9 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -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 "" diff --git a/src/main.rs b/src/main.rs index 69df18e8..7a5fac5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); diff --git a/src/routes/errors.rs b/src/routes/errors.rs new file mode 100644 index 00000000..68ca682e --- /dev/null +++ b/src/routes/errors.rs @@ -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" + })) +} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 501c774c..4787b4d2 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -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; diff --git a/templates/errors/404.html.tera b/templates/errors/404.html.tera new file mode 100644 index 00000000..413374a3 --- /dev/null +++ b/templates/errors/404.html.tera @@ -0,0 +1,6 @@ +{% extends "errors/base" %} + +{% block error %} +

{{ "We couldn't find this page." | _ }}

+

{{ "The link that led you here may be broken." | _ }}

+{% endblock error %}