From ae0342ebd464093f82e509aece2d4b1f481b3553 Mon Sep 17 00:00:00 2001 From: Michal Date: Wed, 15 Aug 2018 12:14:06 +0200 Subject: [PATCH 1/1] Catch all exceptions in JS function updateUI It fails when offline data is processed. It is important that offline data are processed entirely and only once. If the code crashes in the middle, due to an exception, the same offline queue will be replayed next time, causing some coffees to be accounted multiple times and some maybe never accounted. --- templates/main.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/templates/main.js b/templates/main.js index ca89d02..f0b50e1 100644 --- a/templates/main.js +++ b/templates/main.js @@ -34,21 +34,26 @@ var flavorChosen; // call this function. This function updates the UI to match the state. function updateUI() { - if (updateRemote === undefined) { - update("remote", "
Server offline...
"); - document.getElementById("local").style.display = "block"; - loadRemote(); - } else { - document.getElementById("local").style.display = "none"; - - if (id_user !== undefined) { - document.getElementById("nextStep").innerHTML = "Now select a beverage on the coffee machine…"; + try { + if (updateRemote === undefined) { + update("remote", "
Server offline...
"); + document.getElementById("local").style.display = "block"; + loadRemote(); } else { - document.getElementById("nextStep").innerHTML = "Enjoy your " + flavorChosen + "!"; - } + document.getElementById("local").style.display = "none"; + + if (id_user !== undefined) { + document.getElementById("nextStep").innerHTML = "Now select a beverage on the coffee machine…"; + } else { + document.getElementById("nextStep").innerHTML = "Enjoy your " + flavorChosen + "!"; + } - if (timeToLogout !== undefined) - document.getElementById("logout_button").innerHTML = '
logout
(' + timeToLogout + ' s)'; + if (timeToLogout !== undefined) + document.getElementById("logout_button").innerHTML = '
logout
(' + timeToLogout + ' s)'; + } + } + catch (err) { + console.log("Error: ", err); } } -- 2.39.2