From 4dd7adc1fd1154b21d0581eb58482c0a6876b871 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 8 Dec 2020 19:02:53 +0000 Subject: [PATCH] --- ayanova/devdocs/todo.txt | 6 +++- ayanova/src/api/errorhandler.js | 28 +++++++++++++------ .../components/extension-export-control.vue | 4 ++- ayanova/src/main.js | 3 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index 4fafdc77..816fa343 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -28,7 +28,11 @@ ACTIONS: Remove the routes that were being used for inside and outside user lists as they are no longer reqd. $profit - +todo: throw new Error() code *MUST* put only a string into the constructor of error. Putting a object is wrong and will result in errors that say "Error: [object Object]" + Search for all instances of throw new Error and ensure it's a string not an object, use stringify if necessary when all else fails + or a central function that turns any error object into a human readable message and inserts that into the error text + See extension-export-control.vue line 45 for example + todo: seeder subcontractor user no vendor attached? todo: deleting customer must attempt to delete the following as they are entered "in" form and not selected externally so they are part of Customer and should delete with it: diff --git a/ayanova/src/api/errorhandler.js b/ayanova/src/api/errorhandler.js index 807615d6..52ef352e 100644 --- a/ayanova/src/api/errorhandler.js +++ b/ayanova/src/api/errorhandler.js @@ -68,18 +68,23 @@ function dealWithError(msg, vm) { // and return human readable text // function decodeError(e, vm) { - // console.log("decodeError The e object is an object:"); - // //console.log(JSON.stringify(e)); - // console.log(typeof e === "object"); - - //empty? - // console.log("e instanceof Error ", e instanceof Error); + // console.log("decodeError full e object as is: "); // console.log(e); + // console.log("decodeError full e object stringified: ", JSON.stringify(e)); + // console.log("decodeError is typeof:", typeof e); + // console.log("decodeError e is instanceof Error ", e instanceof Error); + // console.log( + // "decodeError e is a string already: ", + // window.$gz.util.isString(e) + // ); - //console.log("Object.keys(e)", Object.keys(e)); + //already a string? + if (window.$gz.util.isString(e)) { + return e; //nothing to do here, already a string + } - //an Error object? if (e instanceof Error) { + //an Error object? return `Error - Name:${e.name}, Message:${e.message}`; } @@ -177,6 +182,13 @@ export default { handleFormError(err, vm) { //called inside forms when things go unexpectedly wrong dealWithError(decodeError(err, vm), vm); + }, + ///////////////////////////////////////////////// + // decode error into string suitable to display + // + errorToString(err, vm) { + //called inside forms when things go unexpectedly wrong + return decodeError(err, vm); } }; /* diff --git a/ayanova/src/components/extension-export-control.vue b/ayanova/src/components/extension-export-control.vue index a6d3778d..3cc377da 100644 --- a/ayanova/src/components/extension-export-control.vue +++ b/ayanova/src/components/extension-export-control.vue @@ -42,7 +42,8 @@ export default { //call api route let res = await window.$gz.api.upsert(url, body); if (res.error) { - throw new Error(res.error); + //Error object constructor must be a string + throw new Error(window.$gz.errorHandler.errorToString(res, vm)); } let href = window.$gz.api.genericDownloadUrl( @@ -55,6 +56,7 @@ export default { } } catch (error) { window.$gz.errorHandler.handleFormError(error, vm); + window.$gz.eventBus.$emit("notify-error", vm.$ay.t("JobFailed")); } } }, diff --git a/ayanova/src/main.js b/ayanova/src/main.js index ba6a562b..0638012e 100644 --- a/ayanova/src/main.js +++ b/ayanova/src/main.js @@ -237,7 +237,8 @@ Vue.prototype.$ay = { return locale.currencyLocalized(value); } }; - +//disable the devtools nag +Vue.config.devtools = false; new Vue({ vuetify: Vuetify, router,