add error catching to unlockDoor method, add event handler to delay open button

master
Bryan 2020-12-20 12:33:48 -06:00
parent 06bef4ad75
commit 42952d70c4
1 changed files with 4 additions and 6 deletions

View File

@ -23,9 +23,9 @@
// make fetch function that calls cgi script with attributes (device id, api key, delay)
const unlockDoor = (e, dID, aK, d) => {
fetch(`${unlockUrl}?deviceID=${dID}&apiKey=${aK}&delay=${d}`)
// fetch(unlockUrl)
.then(response => response.text())
.then(data => messageContainer.innerHTML = data);
.then(response => response.json())
.then(data => messageContainer.innerHTML = data.message)
.catch(error => messageContainer.innerHTML = `Error: ${error}`)
}
const setSettings = () => {
@ -75,9 +75,7 @@
unlockButton.addEventListener("click", (e) => unlockDoor(e, deviceID, apiKey, 0));
delayUnlockButton.addEventListener("click", function () {
messageContainer.innerHTML = "Delay Unlock";
});
delayUnlockButton.addEventListener("click", (e) => unlockDoor(e, deviceID, apiKey, delay));
document.body.onload = setSettings;
let date = new Date();