From: Adam Dullage Date: Mon, 25 Jul 2022 11:53:58 +0000 (+0100) Subject: Added toast message for unhandled server errors. Resolves #1. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=58b292ff879d1357c9f8212304e813e2ba167096;p=flatnotes.git Added toast message for unhandled server errors. Resolves #1. --- diff --git a/flatnotes/src/api.js b/flatnotes/src/api.js index 4436eb8..5006254 100644 --- a/flatnotes/src/api.js +++ b/flatnotes/src/api.js @@ -33,6 +33,7 @@ api.interceptors.response.use( window.location.pathname + window.location.search )}` ); + error.handled = true; } return Promise.reject(error); } diff --git a/flatnotes/src/components/App.js b/flatnotes/src/components/App.js index 8f4d64d..98d22f7 100644 --- a/flatnotes/src/components/App.js +++ b/flatnotes/src/components/App.js @@ -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"); diff --git a/flatnotes/src/components/App.vue b/flatnotes/src/components/App.vue index 93153ef..235bf61 100644 --- a/flatnotes/src/components/App.vue +++ b/flatnotes/src/components/App.vue @@ -218,7 +218,7 @@ - + diff --git a/flatnotes/src/components/RecentlyModified.vue b/flatnotes/src/components/RecentlyModified.vue index 2403c37..230bf2e 100644 --- a/flatnotes/src/components/RecentlyModified.vue +++ b/flatnotes/src/components/RecentlyModified.vue @@ -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"); + } }); }, diff --git a/package-lock.json b/package-lock.json index 2252f30..d4c4763 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 0f6c78b..f2c49f0 100644 --- a/package.json +++ b/package.json @@ -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",