Added error messages

This commit is contained in:
2025-05-17 10:32:33 +03:00
parent e21ba3e213
commit 8a1aa398d9
4 changed files with 20 additions and 2 deletions
+4
View File
@@ -31,14 +31,18 @@ commit.ondblclick = async function () {
}
});
if (!response.ok) {
alert(`Add unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`);
} else {
this.style.backgroundColor = "blue";
window.location.href = "/app";
}
} catch (error) {
alert(`Add unsuccessful. ${error.message}`);
console.error(error.message);
}
} else {
alert("Sensor name can't be null.");
}
};
+6
View File
@@ -28,11 +28,13 @@ setEventListeners(remove, async () => {
method: "DELETE"
});
if (!response.ok) {
alert(`Remove unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`);
} else {
window.location.href = "/app";
}
} catch (error) {
alert(`Remove unsuccessful. ${error.message}`);
console.error(error.message);
}
});
@@ -56,13 +58,17 @@ setEventListeners(commit, async () => {
}
});
if (!response.ok) {
alert(`Edit unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`);
} else {
window.location.href = "/app";
}
} catch (error) {
alert(`Edit unsuccessful. ${error.message}`);
console.error(error.message);
}
} else {
alert("Nothing to commit.");
}
});
+5 -1
View File
@@ -28,7 +28,11 @@ setEventListeners(upload, async () => {
method: 'POST',
body: formData
}).then((response) => {
location.reload();
if (!response.ok) {
alert(`Upload unsuccessful. ${response.status}`);
} else {
location.reload();
}
});
}
const onSelectFile = () => upload(input.files[0]);
+5 -1
View File
@@ -32,7 +32,11 @@ setEventListeners(upload, async () => {
method: 'POST',
body: formData
}).then((response) => {
location.reload();
if (!response.ok) {
alert(`Upload unsuccessful. ${response.status}`);
} else {
location.reload();
}
});
}
const onSelectFile = () => upload(input.files[0]);