From b758cdad9a421b9619f11d31a92a9cb494e74158 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 8 Apr 2019 21:15:14 +0000 Subject: [PATCH] --- ayanova/devdocs/todo.txt | 1 + ayanova/src/api/errorhandler.js | 33 ++++++++++++++++----- ayanova/src/api/gzvalidate.js | 2 +- ayanova/src/views/inventory-widget-edit.vue | 15 ++++++---- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index 155073c4..d50e364a 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -28,6 +28,7 @@ ISSUE: need to display multiple types of messages, best way to do that?? - Application errors - Make them show with the server error box, rejig it as a generic error box - App errors don't need to survive page reload or api call, if they are that serious then they would be notifications instead + - clearing server errors does not necessarily clear message box errors? - Notifications, stuff that you want to know is there and can go and look at but isn't urgent enough to put in the users face - Used for notification system, non-urgent system messages, direct messages from users etc, anything that isn't immediately important - This seems like an application wide thing so maybe a bell icon that takes to another area of the program, or opens a div at the top or bottom of the page?? diff --git a/ayanova/src/api/errorhandler.js b/ayanova/src/api/errorhandler.js index a6dddacc..1595e3b0 100644 --- a/ayanova/src/api/errorhandler.js +++ b/ayanova/src/api/errorhandler.js @@ -6,9 +6,9 @@ var devModeShowErrors = false; //////////////////////////////////////////////////////// // -// Log and optionally display errors -// -function dealWithError(msg, displayToUser) { +// Localize, Log and optionally display errors +// return localized message in case caller needs it +function dealWithError(msg, form) { msg = locale.translateString(msg); //In some cases the error may not be localizable, if this is not a debug run then it should show without the ?? that localizing puts in keys not found //so it's not as wierd looking to the user @@ -16,9 +16,22 @@ function dealWithError(msg, displayToUser) { msg = msg.replace("??", ""); } store.commit("logItem", msg); - if (displayToUser || devModeShowErrors) { + if (devModeShowErrors) { alert("~" + msg); } + + //If a form instance was provided (vue instance) + //then put the error into it + if (form) { + if (form.$gzdevmode()) { + //make sure appError is defined on data + if (!form.$_.has(form, "appError")) { + throw "DEV ERROR errorHandler::dealWithError -> appError seems to be missing from form's vue data object"; + } + } + form.appError = msg; + form.$gzv.SetErrorBoxErrors(form); + } } export default { developmentModeShowErrorsImmediately(showErrorsImmediately) { @@ -63,12 +76,16 @@ export default { } dealWithError(msg); }, - handleFormError(err, displayToUser) { - //called inside forms when things go wrong but are handled + ///////////////////////////////////////////////// + // Localize, log and return error + // + handleFormError(err, form) { + //called inside forms when things go wrong + //returns the localized message in case the form wants to display it as well if (err instanceof Error && err.message) { - dealWithError(err.message, displayToUser); + dealWithError(err.message, form); } else { - dealWithError(err.toString(), displayToUser); + dealWithError(err.toString(), form); } } }; diff --git a/ayanova/src/api/gzvalidate.js b/ayanova/src/api/gzvalidate.js index 313fff22..2777718e 100644 --- a/ayanova/src/api/gzvalidate.js +++ b/ayanova/src/api/gzvalidate.js @@ -272,7 +272,7 @@ export default { // SERVER ERRORS // Process and return server errors if any for form and field specified ServerErrors(v, ref) { - //CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDE DATA ATTRIBUTES ETC + //CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC if (v.$gzdevmode()) { //make sure serverErrors is defined on data if (!v.$_.has(v, "serverError")) { diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index 5ec3b99c..c5bb2cf3 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -176,7 +176,7 @@ export default { obj: {}, serverError: {}, errorBoxMessage: null, - appError:null, + appError: null, formReady: false }; }, @@ -187,14 +187,19 @@ export default { getDataFromApi() { var url = "Widget/" + this.$route.params.id; var that = this; - this.$gzv.DeleteAllErrorBoxErrors(this); + this.$gzv.DeleteAllErrorBoxErrors(this); this.$gzapi .get(url) .then(res => { - this.obj = res.data; + if (res.error) { + that.serverError = res.error; + that.$gzv.SetErrorBoxErrors(that); + } else { + that.obj = res.data; + } }) .catch(function(error) { - that.$gzHandleFormError(error, true); + that.$gzHandleFormError(error, that); }); }, submit() { @@ -225,7 +230,7 @@ export default { } }) .catch(function(error) { - that.$gzHandleFormError(error, true); + that.$gzHandleFormError(error, that); }); } } //end of submit()