]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Catch all exceptions in JS function updateUI
authorMichal <michal.sojka@cvut.cz>
Wed, 15 Aug 2018 10:14:06 +0000 (12:14 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 16 Aug 2018 17:11:26 +0000 (19:11 +0200)
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

index ca89d02a78aa56a695cda08534da5f946f8f3794..f0b50e1e5f3de1a735a17bbeabc21914c6256f1c 100644 (file)
@@ -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", "<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();
         } 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 = '<br>logout<br>(' + timeToLogout + ' s)';
+            if (timeToLogout !== undefined)
+                document.getElementById("logout_button").innerHTML = '<br>logout<br>(' + timeToLogout + ' s)';
+        }
+    }
+    catch (err) {
+        console.log("Error: ", err);
     }
 }