diff --git a/ayanova/src/api/apiutil.js b/ayanova/src/api/apiutil.js index 06cd878e..4834da2d 100644 --- a/ayanova/src/api/apiutil.js +++ b/ayanova/src/api/apiutil.js @@ -35,6 +35,7 @@ var devShowUnknownError = function(error) { export default { status(response) { + //Handle expected api errors if (response.status == 401) { //must reject if not authorized return Promise.reject(new Error("401 - NOT AUTHORIZED")); @@ -43,6 +44,7 @@ export default { if (response.status >= 200 && response.status < 300) { return Promise.resolve(response); } else { + //log unhandled api error store.commit( "logItem", "API error: status=" + @@ -52,10 +54,7 @@ export default { ", url=" + response.url ); - - //TODO: If no viable data to return then should reject, otherwise should resolve regardless - //Nope because we will never get here if nothing at all was returned so what is this actually doing?? - + //let it float up for dealing with by caller(s) return Promise.resolve(response); } }, diff --git a/ayanova/src/api/gzutil.js b/ayanova/src/api/gzutil.js new file mode 100644 index 00000000..942744c0 --- /dev/null +++ b/ayanova/src/api/gzutil.js @@ -0,0 +1,21 @@ +/* Xeslint-disable */ + +///////////////////////////////// +// General utility library +// +export default { + /////////////////////////////// + // CLEAN OBJECT + // Clear all properties from object without resorting to assigning a new object (o={}) + // which can be problematic in some cases (IE bugs, watched data items in forms etc) + + RemoveAllPropertiesFromObject(o) { + for (var variableKey in o) { + if (o.hasOwnProperty(variableKey)) { + delete o[variableKey]; + } + } + } + + //new functions above here +}; diff --git a/ayanova/src/api/gzvalidate.js b/ayanova/src/api/gzvalidate.js index 9843f960..2016e0da 100644 --- a/ayanova/src/api/gzvalidate.js +++ b/ayanova/src/api/gzvalidate.js @@ -485,7 +485,7 @@ Here are all the API level error codes that can be returned by the API server: //If there are no more errors in details then remove the whole thing as it's no longer required if (v.serverError.details && v.serverError.details.length < 1) { if (v.serverError.code == "2200") { - this.RemoveAllProperties(v.serverError); + v.$gzutil.RemoveAllPropertiesFromObject(v.serverError); } } diff --git a/ayanova/src/main.js b/ayanova/src/main.js index 3df53306..11a01477 100644 --- a/ayanova/src/main.js +++ b/ayanova/src/main.js @@ -10,18 +10,22 @@ import "./registerServiceWorker"; import errorHandler from "./api/errorhandler"; import NProgress from "nprogress"; import "nprogress/nprogress.css"; -import gzdateandtimepicker from "./components/gzdateandtimepicker.vue"; import dayjs from "dayjs"; import lodash from "./libs/lodash.min.js"; +//my libs +import gzutil from "./api/gzutil"; import locale from "./api/locale"; import gzapi from "./api/apiutil"; import gzvalidate from "./api/gzvalidate"; import "@/assets/css/main.css"; +import gzdateandtimepicker from "./components/gzdateandtimepicker.vue"; + ///////////////////////////////////////////////////////////////// // LIBS AND GLOBAL ITEMS // (https://medium.com/js-dojo/use-any-javascript-library-with-vue-js-3f7e2a4974a8) // +Object.defineProperty(Vue.prototype, "$gzutil", { value: gzutil }); Object.defineProperty(Vue.prototype, "$dayjs", { value: dayjs }); Object.defineProperty(Vue.prototype, "$_", { value: lodash }); Object.defineProperty(Vue.prototype, "$gzlocale", { value: locale }); diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index fd21d02c..186c5e81 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -196,17 +196,13 @@ export default { var url = "Widget/" + this.$route.params.id; //clear any errors that might be around from previous submit - this.$gzv.RemoveAllProperties(this.serverError); + this.$gzutil.RemoveAllPropertiesFromObject(this.serverError); this.$gzapi .upsert(url, this.obj) .then(res => { - if (res.error) { - //debugger; - //Set errors so form can pick them up for controls in canHasServerErrors - that.serverError = res.error; - // that.$refs.form.resetValidation(); - // that.$refs.form.validate(); + if (res.error) { + that.serverError = res.error; } else { //Logic for detecting if a post or put: if id then it was a post, if no id then it was a put if (res.id) {