mirror of
https://github.com/SinTan1729/chhoto-url
synced 2025-04-28 11:56:52 -05:00
fix: Better response on error when shortlink is not provided
This commit is contained in:
parent
4eb88f3beb
commit
084334cd11
1 changed files with 6 additions and 2 deletions
|
@ -123,9 +123,12 @@ pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||||
len = 4;
|
len = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if chunks.shortlink.is_empty() {
|
let shortlink_provided = if chunks.shortlink.is_empty() {
|
||||||
chunks.shortlink = gen_link(style, len);
|
chunks.shortlink = gen_link(style, len);
|
||||||
}
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
if validate_link(chunks.shortlink.as_str()) {
|
if validate_link(chunks.shortlink.as_str()) {
|
||||||
match database::add_link(chunks.shortlink.clone(), chunks.longlink, db) {
|
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) => {
|
Err(error) => {
|
||||||
if error.sqlite_error().map(|err| err.extended_code)
|
if error.sqlite_error().map(|err| err.extended_code)
|
||||||
== Some(SQLITE_CONSTRAINT_UNIQUE)
|
== Some(SQLITE_CONSTRAINT_UNIQUE)
|
||||||
|
&& shortlink_provided
|
||||||
{
|
{
|
||||||
(false, String::from("Short URL is already in use!"))
|
(false, String::from("Short URL is already in use!"))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue