This commit is contained in:
2019-04-04 18:05:59 +00:00
parent 67d46052c7
commit 108338dbeb
5 changed files with 33 additions and 13 deletions

View File

@@ -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);
}
},

21
ayanova/src/api/gzutil.js Normal file
View File

@@ -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
};

View File

@@ -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);
}
}

View File

@@ -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 });

View File

@@ -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();
} 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) {