errors: add hagrid templated error handler
This commit is contained in:
parent
9f4b82a9b1
commit
dd6c69f11d
|
@ -0,0 +1,5 @@
|
|||
{{#> layout }}
|
||||
<h2>Error 503</h2>
|
||||
|
||||
<tt>Whoa there! Slow down a little!</tt>
|
||||
{{/layout}}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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/<code>/<template>")]
|
||||
fn errors(
|
||||
code: u16,
|
||||
template: String,
|
||||
) -> Result<Custom<Template>> {
|
||||
if !template.chars().all(|x| x == '-' || char::is_ascii_alphabetic(&x)) {
|
||||
return Err(failure::err_msg("bad request"));
|
||||
}
|
||||
let status_code = Status::from_code(code)
|
||||
.ok_or(failure::err_msg("bad request"))?;
|
||||
let response_body = Template::render(
|
||||
format!("errors/{}-{}", code, template),
|
||||
templates::General::default()
|
||||
);
|
||||
Ok(Custom(status_code, response_body))
|
||||
}
|
||||
|
||||
pub fn serve() -> Result<()> {
|
||||
Err(rocket_factory(rocket::ignite())?.launch().into())
|
||||
}
|
||||
|
@ -326,6 +344,7 @@ fn rocket_factory(rocket: rocket::Rocket) -> Result<rocket::Rocket> {
|
|||
usage,
|
||||
files,
|
||||
stats,
|
||||
errors,
|
||||
// VKSv1
|
||||
vks_api::vks_v1_by_email,
|
||||
vks_api::vks_v1_by_fingerprint,
|
||||
|
|
Loading…
Reference in New Issue