From 86ec787d966692f2b5d4ced3e282122dfd120062 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Tue, 2 Apr 2024 21:26:18 -0500 Subject: [PATCH] fix: Errors in script.js --- resources/static/script.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/static/script.js b/resources/static/script.js index 49c4392..1640e99 100644 --- a/resources/static/script.js +++ b/resources/static/script.js @@ -173,6 +173,7 @@ const submitForm = () => { }; const url = prepSubdir("/api/new"); + let ok = false; fetch(url, { method: "POST", @@ -182,15 +183,14 @@ const submitForm = () => { body: JSON.stringify(data), }) .then(res => { - if (!res.ok) { - showAlert(res.text(), "red"); - return "error"; + ok = res.ok; + return res.text(); + }) + .then(text => { + if (!ok) { + showAlert(text, "red"); } else { - return res.text(); - } - }).then(text => { - if (text != "error") { copyShortUrl(text); longUrl.value = ""; shortUrl.value = "";