From 084334cd114edf2dddc9f91b9e59a2e135e5e8dd Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Wed, 23 Apr 2025 15:45:41 -0500 Subject: [PATCH] fix: Better response on error when shortlink is not provided --- actix/src/utils.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/actix/src/utils.rs b/actix/src/utils.rs index 86a77be..8b4aac5 100644 --- a/actix/src/utils.rs +++ b/actix/src/utils.rs @@ -123,9 +123,12 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) { len = 4; } - if chunks.shortlink.is_empty() { + let shortlink_provided = if chunks.shortlink.is_empty() { chunks.shortlink = gen_link(style, len); - } + false + } else { + true + }; if validate_link(chunks.shortlink.as_str()) { match database::add_link(chunks.shortlink.clone(), chunks.longlink, db) { @@ -133,6 +136,7 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) { Err(error) => { if error.sqlite_error().map(|err| err.extended_code) == Some(SQLITE_CONSTRAINT_UNIQUE) + && shortlink_provided { (false, String::from("Short URL is already in use!")) } else {