diff options
author | cel 🌸 <cel@blos.sm> | 2023-01-16 05:54:09 +0000 |
---|---|---|
committer | cel 🌸 <cel@blos.sm> | 2023-01-16 05:54:09 +0000 |
commit | 8d176d8c076a5e71c210ee7464512b983659e1a0 (patch) | |
tree | 6645f81bba2c71214320d3c6b5517039c41ef58d /src/main.rs | |
parent | 67790fcb2f593dae9e57c0f6accf0335b5d80c43 (diff) | |
download | blossom-8d176d8c076a5e71c210ee7464512b983659e1a0.tar.gz blossom-8d176d8c076a5e71c210ee7464512b983659e1a0.tar.bz2 blossom-8d176d8c076a5e71c210ee7464512b983659e1a0.zip |
refactor error handler (LOL)
Diffstat (limited to 'src/main.rs')
-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?; |