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) { if (!response.ok) {
alert(`Add unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`); throw new Error(`Response status: ${response.status}`);
} else { } else {
this.style.backgroundColor = "blue"; this.style.backgroundColor = "blue";
window.location.href = "/app"; window.location.href = "/app";
} }
} catch (error) { } catch (error) {
alert(`Add unsuccessful. ${error.message}`);
console.error(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" method: "DELETE"
}); });
if (!response.ok) { if (!response.ok) {
alert(`Remove unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`); throw new Error(`Response status: ${response.status}`);
} else { } else {
window.location.href = "/app"; window.location.href = "/app";
} }
} catch (error) { } catch (error) {
alert(`Remove unsuccessful. ${error.message}`);
console.error(error.message); console.error(error.message);
} }
}); });
@@ -56,13 +58,17 @@ setEventListeners(commit, async () => {
} }
}); });
if (!response.ok) { if (!response.ok) {
alert(`Edit unsuccessful. ${response.status}`);
throw new Error(`Response status: ${response.status}`); throw new Error(`Response status: ${response.status}`);
} else { } else {
window.location.href = "/app"; window.location.href = "/app";
} }
} catch (error) { } catch (error) {
alert(`Edit unsuccessful. ${error.message}`);
console.error(error.message); console.error(error.message);
} }
} else {
alert("Nothing to commit.");
} }
}); });
+4
View File
@@ -28,7 +28,11 @@ setEventListeners(upload, async () => {
method: 'POST', method: 'POST',
body: formData body: formData
}).then((response) => { }).then((response) => {
if (!response.ok) {
alert(`Upload unsuccessful. ${response.status}`);
} else {
location.reload(); location.reload();
}
}); });
} }
const onSelectFile = () => upload(input.files[0]); const onSelectFile = () => upload(input.files[0]);
+4
View File
@@ -32,7 +32,11 @@ setEventListeners(upload, async () => {
method: 'POST', method: 'POST',
body: formData body: formData
}).then((response) => { }).then((response) => {
if (!response.ok) {
alert(`Upload unsuccessful. ${response.status}`);
} else {
location.reload(); location.reload();
}
}); });
} }
const onSelectFile = () => upload(input.files[0]); const onSelectFile = () => upload(input.files[0]);