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.
// call this function. This function updates the UI to match the state.
function updateUI()
{
// call this function. This function updates the UI to match the state.
function updateUI()
{
- if (updateRemote === undefined) {
- update("remote", "<center>Server offline...</center>");
- 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", "<center>Server offline...</center>");
+ document.getElementById("local").style.display = "block";
+ loadRemote();
- 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 = '<br>logout<br>(' + timeToLogout + ' s)';
+ if (timeToLogout !== undefined)
+ document.getElementById("logout_button").innerHTML = '<br>logout<br>(' + timeToLogout + ' s)';
+ }
+ }
+ catch (err) {
+ console.log("Error: ", err);