Added toast message for unhandled server errors. Resolves #1.
authorAdam Dullage <redacted>
Mon, 25 Jul 2022 11:53:58 +0000 (12:53 +0100)
committerAdam Dullage <redacted>
Mon, 25 Jul 2022 11:53:58 +0000 (12:53 +0100)
flatnotes/src/api.js
flatnotes/src/components/App.js
flatnotes/src/components/App.vue
flatnotes/src/components/RecentlyModified.vue
package-lock.json
package.json

index 4436eb867194a93f8fca84d81800c10b5e8b32b3..50062541e33b08b47f36cab541afdc86ad7a6424 100644 (file)
@@ -33,6 +33,7 @@ api.interceptors.response.use(
           window.location.pathname + window.location.search
         )}`
       );
+      error.handled = true;
     }
     return Promise.reject(error);
   }
index 8f4d64dd04e2eef3d471efc6a2ca9fb3e3c2546d..98d22f740571d1b8cb1740ff409602909e8c0163 100644 (file)
@@ -98,11 +98,15 @@ export default {
           parent.navigate(redirectPath || "/");
         })
         .catch(function(error) {
-          if ([400, 422].includes(error.response.status)) {
+          if (error.handled) {
+            return;
+          } else if ([400, 422].includes(error.response.status)) {
             parent.$bvToast.toast("Incorrect Username or Password ✘", {
               variant: "danger",
               noCloseButton: true,
             });
+          } else {
+            parent.unhandledServerErrorToast();
           }
         })
         .finally(function() {
@@ -142,6 +146,11 @@ export default {
               )
             );
           });
+        })
+        .catch(function(error) {
+          if (!error.handled) {
+            parent.unhandledServerErrorToast();
+          }
         });
     },
 
@@ -168,6 +177,11 @@ export default {
             response.data.content
           );
           parent.updateDocumentTitle();
+        })
+        .catch(function(error) {
+          if (!error.handled) {
+            parent.unhandledServerErrorToast();
+          }
         });
     },
 
@@ -274,8 +288,12 @@ export default {
           })
           .then(this.saveNoteResponseHandler)
           .catch(function(error) {
-            if (error.response.status == 409) {
+            if (error.handled) {
+              return;
+            } else if (error.response.status == 409) {
               parent.existingFilenameToast();
+            } else {
+              parent.unhandledServerErrorToast();
             }
           });
       }
@@ -292,8 +310,12 @@ export default {
           })
           .then(this.saveNoteResponseHandler)
           .catch(function(error) {
-            if (error.response.status == 409) {
+            if (error.handled) {
+              return;
+            } else if (error.response.status == 409) {
               parent.existingFilenameToast();
+            } else {
+              parent.unhandledServerErrorToast();
             }
           });
       }
@@ -357,6 +379,11 @@ export default {
                   variant: "success",
                   noCloseButton: true,
                 });
+              })
+              .catch(function(error) {
+                if (!error.handled) {
+                  parent.unhandledServerErrorToast();
+                }
               });
           }
         });
@@ -384,10 +411,22 @@ export default {
       //   this.saveNote();
       // }
     },
+
+    unhandledServerErrorToast: function() {
+      this.$bvToast.toast(
+        "Unknown error communicating with the server. Please try again.",
+        {
+          title: "Unknown Error",
+          variant: "danger",
+          noCloseButton: true,
+        }
+      );
+    },
   },
 
   created: function() {
     EventBus.$on("navigate", this.navigate);
+    EventBus.$on("unhandledServerError", this.unhandledServerErrorToast);
     document.addEventListener("keydown", this.keyboardShortcuts);
 
     let token = localStorage.getItem("token");
index 93153ef717c8aa83b844dd2795d52a7c25a9e524..235bf613a8231b2f6c02396b3946f66d9e94ae57 100644 (file)
       </div>
 
       <!-- Home -->
-      <RecentlyModified v-if="currentView == views.home"/>
+      <RecentlyModified v-if="currentView == views.home" />
     </div>
   </div>
 </template>
index 2403c37d83a512a76635594d7bb359555ab5f36f..230bf2e9190e0aa4c1e7e4a54a4bcdd6ea652955 100644 (file)
@@ -51,6 +51,11 @@ export default {
           response.data.forEach(function (note) {
             parent.notes.push(new Note(note.filename, note.lastModified));
           });
+        })
+        .catch(function (error) {
+          if (!error.handled) {
+            EventBus.$emit("unhandledServerError");
+          }
         });
     },
 
index 2252f303318bd6b9b29e13295e563184e60e03a8..d4c476374e4c5c2afc183ecb2ad6931fd9f904d5 100644 (file)
@@ -15,6 +15,7 @@
         "bootstrap": "4.6",
         "bootstrap-vue": "^2.21.2",
         "parcel-bundler": "^1.12.5",
+        "portal-vue": "^2.1.7",
         "sass": "^1.37.5",
         "vue": "^2.6.14",
         "vue-hot-reload-api": "^2.3.4",
index 0f6c78be97f01d431489b35d5702e15f2e0dbad4..f2c49f08d01ce752792f3166f17d552c18d006d6 100644 (file)
@@ -18,6 +18,7 @@
     "bootstrap": "4.6",
     "bootstrap-vue": "^2.21.2",
     "parcel-bundler": "^1.12.5",
+    "portal-vue": "^2.1.7",
     "sass": "^1.37.5",
     "vue": "^2.6.14",
     "vue-hot-reload-api": "^2.3.4",
git clone https://git.99rst.org/PROJECT