Browse Source

reset client on network error

Martin Kunz 5 years ago
parent
commit
168b5711cf
2 changed files with 15 additions and 1 deletions
  1. 9 1
      webroot/index.html
  2. 6 0
      webroot/js/util.js

+ 9 - 1
webroot/index.html

@@ -4,6 +4,7 @@
     <meta charset="utf-8">
     <title>Vue.js markdown editor example</title>
     <link rel="stylesheet" href="css/style.css">
+    <script src="js/util.js"></script>
     <script src="js/moment.js"></script>
     <script src="js/vue.js"></script>
 </head>
@@ -50,6 +51,7 @@
             },
             update: function (event) {
                 fetch('/log/'+this.lastID, {method: "GET"})
+                    .then(handleErrors)
                     .then((response) => {
                         return response.json();
                     })
@@ -57,7 +59,13 @@
                         console.log(JSON.stringify(myJson));
                         this.$data.log=this.$data.log.concat(myJson.entries);
                         this.$data.lastID=myJson.lastID;
-                    });
+                    })
+                    .catch(error => {
+                        this.$data.lastID=0;3
+                        this.$data.log=[];
+                        console.log(error)
+                    } );
+
             }
         }
     })

+ 6 - 0
webroot/js/util.js

@@ -0,0 +1,6 @@
+function handleErrors(response) {
+    if (!response.ok) {
+        throw Error(response.statusText);
+    }
+    return response;
+}