Added error messages
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user