Plume/src/routes/errors.rs

38 lines
905 B
Rust
Raw Normal View History

2018-06-18 17:59:49 +02:00
use rocket_contrib::Template;
2018-06-21 11:58:54 +02:00
use rocket::Request;
use rocket::request::FromRequest;
use plume_models::users::User;
2018-06-18 17:59:49 +02:00
#[catch(404)]
2018-06-21 11:58:54 +02:00
fn not_found(req: &Request) -> Template {
let user = User::from_request(req).succeeded();
2018-06-18 17:59:49 +02:00
Template::render("errors/404", json!({
2018-06-21 11:58:54 +02:00
"error_message": "Page not found",
"account": user
2018-06-18 17:59:49 +02:00
}))
}
#[catch(500)]
2018-06-21 11:58:54 +02:00
fn server_error(req: &Request) -> Template {
let user = User::from_request(req).succeeded();
2018-06-18 17:59:49 +02:00
Template::render("errors/500", json!({
2018-06-21 11:58:54 +02:00
"error_message": "Server error",
"account": user
2018-06-18 17:59:49 +02:00
}))
}
2018-06-24 18:58:57 +02:00
#[derive(FromForm)]
pub struct Uri {
target: String,
}
#[post("/csrf-violation?<uri>")]
fn csrf_violation(uri: Option<Uri>) -> Template {
if let Some(uri) = uri {
eprintln!("Csrf violation while acceding \"{}\"", uri.target)
}
Template::render("errors/csrf", json!({
"error_message":""
}))
}