From dd6c69f11dedb713dc5c0f4aba582b5bfb7000f1 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 11 Jul 2019 22:38:16 +0200 Subject: [PATCH] errors: add hagrid templated error handler --- .../errors/503-rate-limit-web.html.hbs | 5 +++++ hagrid-routes.conf | 14 +++++++++---- src/web/mod.rs | 21 ++++++++++++++++++- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 dist/templates/errors/503-rate-limit-web.html.hbs diff --git a/dist/templates/errors/503-rate-limit-web.html.hbs b/dist/templates/errors/503-rate-limit-web.html.hbs new file mode 100644 index 0000000..105e1ab --- /dev/null +++ b/dist/templates/errors/503-rate-limit-web.html.hbs @@ -0,0 +1,5 @@ +{{#> layout }} +

Error 503

+ + Whoa there! Slow down a little! +{{/layout}} diff --git a/hagrid-routes.conf b/hagrid-routes.conf index 069bb05..f2aee45 100644 --- a/hagrid-routes.conf +++ b/hagrid-routes.conf @@ -100,6 +100,16 @@ location /pks/lookup { proxy_pass http://127.0.0.1:8080; } +location /errors { + internal; + proxy_pass http://127.0.0.1:8080; +} + +location /search { + error_page 503 /errors/503/rate-limit-web; + proxy_pass http://127.0.0.1:8080; +} + location /pks { proxy_pass http://127.0.0.1:8080; } @@ -112,10 +122,6 @@ location /verify { proxy_pass http://127.0.0.1:8080; } -location /search { - proxy_pass http://127.0.0.1:8080; -} - location /upload { proxy_pass http://127.0.0.1:8080; } diff --git a/src/web/mod.rs b/src/web/mod.rs index ef27532..a0ff459 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -1,5 +1,5 @@ use rocket; -use rocket::http::Header; +use rocket::http::{Header, Status}; use rocket::request; use rocket::outcome::Outcome; use rocket::response::NamedFile; @@ -7,6 +7,7 @@ use rocket::config::Config; use rocket_contrib::templates::Template; use rocket::http::uri::Uri; use rocket_contrib::json::JsonValue; +use rocket::response::status::Custom; use serde::Serialize; use handlebars::Handlebars; @@ -310,6 +311,23 @@ fn stats() -> Template { Template::render("about/stats", templates::General::default()) } +#[get("/errors//