fix: Errors in script.js

This commit is contained in:
SinTan1729 2024-04-02 21:26:18 -05:00
parent 30c0b8b50a
commit 86ec787d96
No known key found for this signature in database
GPG Key ID: EB3E68BFBA25C85F

View File

@ -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 = "";