diff --git a/po/plume.pot b/po/plume.pot index 1d36fc3..6eaebfb 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 69df18e..7a5fac5 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 0000000..68ca682 --- /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 501c774..4787b4d 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 0000000..413374a --- /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 %}