From 92671eb0c8528a95440ba18305e8cb158c6f67d7 Mon Sep 17 00:00:00 2001 From: SadlyNotSappho Date: Fri, 22 Mar 2024 11:24:11 -0700 Subject: [PATCH] update error messages in GET /images/ --- src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 950187a..40fc3f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,6 +153,7 @@ async fn login( } } } + #[post("/logout")] async fn logout(cookies: &CookieJar<'_>) -> status::Custom<&'static str> { match cookies.get_private("token") { @@ -323,7 +324,10 @@ async fn toggleperms( } #[get("/images/")] -async fn get_image(image: String, mut db: Connection) -> Result { +async fn get_image( + image: String, + mut db: Connection, +) -> Result> { let mut split = image.split('.').collect::>(); let format = split.pop().unwrap(); let image = split.join("."); @@ -351,13 +355,21 @@ async fn get_image(image: String, mut db: Connection) -> Result Err(match &why.to_string()[..] { - "Format error decoding Png: Invalid PNG signature." => Status::NotAcceptable, - _ => Status::InternalServerError, + "Format error decoding Png: Invalid PNG signature." => { + status::Custom(Status::NotAcceptable, "That file isn't an image.") + } + _ => status::Custom(Status::InternalServerError, "Unknown decoding error"), }), }, - Err(_) => Err(Status::NotFound), + Err(_) => Err(status::Custom( + Status::InternalServerError, + "Unknown decoding error", + )), }, - Err(_) => Err(Status::ImATeapot), + Err(_) => Err(status::Custom( + Status::InternalServerError, + "File not found", + )), } }