diff options
Diffstat (limited to '')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 63a8c10..6efade0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,28 +77,19 @@ async fn contact() -> Template { // posts // } -#[catch(404)] -fn not_found(req: &Request) -> Template { - let message = "i either haven't built this page yet or it looks like you're a little lost"; - Template::render( - "error", - context! { status: "404", req: req.uri(), message: message }, - ) -} - -#[catch(501)] -fn server_error(req: &Request) -> Template { - let message = "it looks like this is not yet here!!!"; - Template::render( - "error", - context! { status: "501", req: req.uri(), message: message }, - ) -} - #[catch(default)] fn error(status: Status, req: &Request) -> Template { + let message; + if status.code == 404 { + message = "i either haven't built this page yet or it looks like you're a little lost"; + } else if status.code == 500 { + message = "omg the server went kaputt!!"; + } else if status.code == 501 { + message = "it looks like this is not yet here!!!"; + } else { + message = "there was an error"; + } let status = format!("{}", status); - let message = "there was an error"; Template::render( "error", context! { status: status, req: req.uri(), message: message }, @@ -110,7 +101,7 @@ async fn main() -> Result<(), rocket::Error> { let _rocket = rocket::build() .attach(Template::fairing()) .mount("/", routes![home, contact]) - .register("/", catchers![not_found, server_error, error]) + .register("/", catchers![error]) .mount("/", FileServer::from(relative!("static"))) .launch() .await?; |