This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* Xeslint-disable */
|
/* Xeslint-disable */
|
||||||
import apiUtil from "./apiutil";
|
import apiUtil from "./gzapi";
|
||||||
import { processLogin, processLogout } from "./authutil";
|
import { processLogin, processLogout } from "./authutil";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import router from "../router";
|
|||||||
import auth from "./auth";
|
import auth from "./auth";
|
||||||
import errorHandler from "./errorhandler";
|
import errorHandler from "./errorhandler";
|
||||||
|
|
||||||
var stringifyPrimitive = function(v) {
|
function stringifyPrimitive(v) {
|
||||||
switch (typeof v) {
|
switch (typeof v) {
|
||||||
case "string":
|
case "string":
|
||||||
return v;
|
return v;
|
||||||
@@ -18,20 +18,55 @@ var stringifyPrimitive = function(v) {
|
|||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
var devShowUnknownError = function(error) {
|
/////////////////////////////////////////////////
|
||||||
|
// Show unexpected errors during development
|
||||||
|
//
|
||||||
|
function devShowUnknownError(error) {
|
||||||
if (errorHandler.devMode) {
|
if (errorHandler.devMode) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.log("apiutil::devShowUnknownError, error is:");
|
console.log("gzapi::devShowUnknownError, error is:");
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.log(error);
|
console.log(error);
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
alert(
|
alert(
|
||||||
"DEV ERROR apiutil::devShowUnknownError - unexpected error during api operation see console "
|
"DEV ERROR gzapi::devShowUnknownError - unexpected error during api operation see console "
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
// Try to handle an api error
|
||||||
|
// return true if handled or false if not
|
||||||
|
//
|
||||||
|
function handleError(action, error, route, reject) {
|
||||||
|
var errorMessage =
|
||||||
|
"API error: " + action + " route =" + route + ", message =" + error.message;
|
||||||
|
store.commit("logItem", errorMessage);
|
||||||
|
|
||||||
|
if (error.message && error.message.includes("401")) {
|
||||||
|
store.commit("logItem", "User is not authorized, redirecting to login");
|
||||||
|
auth.logout();
|
||||||
|
router.push("/login");
|
||||||
|
return reject("Authorization required");
|
||||||
|
}
|
||||||
|
//is it a network error?
|
||||||
|
//https://medium.com/@vinhlh/how-to-handle-networkerror-when-using-fetch-ff2663220435
|
||||||
|
if (error instanceof TypeError) {
|
||||||
|
if (
|
||||||
|
error.message.includes("Failed to fetch") ||
|
||||||
|
error.message.includes("NetworkError") ||
|
||||||
|
error.message.includes("Network request failed")
|
||||||
|
) {
|
||||||
|
store.commit("logItem", "Network error");
|
||||||
|
return reject("Error: unable to contact server");
|
||||||
|
//throw "Error: unable to contact server";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Ideally this should never get called because any issue should be addressed above
|
||||||
|
devShowUnknownError(error);
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
status(response) {
|
status(response) {
|
||||||
@@ -135,7 +170,7 @@ export default {
|
|||||||
store.commit("setHelpURL", "http://localhost:7575/docs/");
|
store.commit("setHelpURL", "http://localhost:7575/docs/");
|
||||||
store.commit(
|
store.commit(
|
||||||
"logItem",
|
"logItem",
|
||||||
"apiutil::APIUrl -> setting to dev. mode: " + store.state.apiUrl
|
"gzapi::APIUrl -> setting to dev. mode: " + store.state.apiUrl
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//production location <protocol>//<hostname>:<port>/
|
//production location <protocol>//<hostname>:<port>/
|
||||||
@@ -149,7 +184,7 @@ export default {
|
|||||||
);
|
);
|
||||||
store.commit(
|
store.commit(
|
||||||
"logItem",
|
"logItem",
|
||||||
"apiutil::APIUrl -> setting to: " + store.state.apiUrl
|
"gzapi::APIUrl -> setting to: " + store.state.apiUrl
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,23 +239,12 @@ export default {
|
|||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
//fundamental error, can't proceed with this call
|
//fundamental error, can't proceed with this call
|
||||||
|
handleError("GET", error, route, reject);
|
||||||
var errorMessage =
|
// {
|
||||||
"API error: GET route =" + route + ", message =" + error.message;
|
// //Ideally this should never get called because any issue should be addressed above by errorHandler
|
||||||
store.commit("logItem", errorMessage);
|
// devShowUnknownError(error);
|
||||||
|
// reject(error);
|
||||||
if (error.message && error.message.includes("401")) {
|
// }
|
||||||
store.commit(
|
|
||||||
"logItem",
|
|
||||||
"User is not authorized, redirecting to login"
|
|
||||||
);
|
|
||||||
auth.logout();
|
|
||||||
router.push("/login");
|
|
||||||
} else {
|
|
||||||
//This should never get called because any issue should be addressed above in a proper error handler
|
|
||||||
devShowUnknownError(error);
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -247,24 +271,13 @@ export default {
|
|||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
|
handleError("UPSERT", error, route, reject);
|
||||||
//fundamental error, can't proceed with this call
|
//fundamental error, can't proceed with this call
|
||||||
|
// if (!handleError("UPSERT", error, route)) {
|
||||||
var errorMessage =
|
// //This should (ideally) never get called because any issue should be addressed above by handleError
|
||||||
"API error: UPSERT route =" + route + ", message =" + error.message;
|
// devShowUnknownError(error);
|
||||||
store.commit("logItem", errorMessage);
|
// reject(error);
|
||||||
|
// }
|
||||||
if (error.message && error.message.includes("401")) {
|
|
||||||
store.commit(
|
|
||||||
"logItem",
|
|
||||||
"User is not authorized, redirecting to login"
|
|
||||||
);
|
|
||||||
auth.logout();
|
|
||||||
router.push("/login");
|
|
||||||
} else {
|
|
||||||
//This should never get called because any issue should be addressed above in a proper error handler
|
|
||||||
devShowUnknownError(error);
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,6 @@ export default {
|
|||||||
// SetErrorBoxErrors
|
// SetErrorBoxErrors
|
||||||
// Gather server errors and set the appropriate keys
|
// Gather server errors and set the appropriate keys
|
||||||
SetErrorBoxErrors(v) {
|
SetErrorBoxErrors(v) {
|
||||||
**THIS**
|
|
||||||
//maybe just put all the code in here and don't call geterrorboxerrors at all as no one else will need to call it anyway
|
//maybe just put all the code in here and don't call geterrorboxerrors at all as no one else will need to call it anyway
|
||||||
var errs = this.ServerErrors(v, "errorbox");
|
var errs = this.ServerErrors(v, "errorbox");
|
||||||
var ret = GetErrorBoxErrors(v, errs);
|
var ret = GetErrorBoxErrors(v, errs);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import store from "../store";
|
import store from "../store";
|
||||||
import roles from "./roles";
|
import roles from "./roles";
|
||||||
import locale from "./locale";
|
import locale from "./locale";
|
||||||
import api from "./apiutil";
|
import api from "./gzapi";
|
||||||
|
|
||||||
function addNavItem(title, icon, route) {
|
function addNavItem(title, icon, route) {
|
||||||
store.commit("addNavItem", {
|
store.commit("addNavItem", {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* ZZeslint-disable */
|
/* ZZeslint-disable */
|
||||||
import store from "../store";
|
import store from "../store";
|
||||||
import apiUtil from "./apiutil";
|
import apiUtil from "./gzapi";
|
||||||
import _ from "../libs/lodash.min.js";
|
import _ from "../libs/lodash.min.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default {
|
|||||||
.then(() => (this.formReady = true))
|
.then(() => (this.formReady = true))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
this.formReady = true;
|
this.formReady = true;
|
||||||
this.$gzerror(err);
|
this.$gzHandleFormError(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export default {
|
|||||||
.then(() => (this.formReady = true))
|
.then(() => (this.formReady = true))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
this.formReady = true; //show the form anyway so we know what's what
|
this.formReady = true; //show the form anyway so we know what's what
|
||||||
this.$gzerror(err);
|
this.$gzHandleFormError(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import lodash from "./libs/lodash.min.js";
|
|||||||
//my libs
|
//my libs
|
||||||
import gzutil from "./api/gzutil";
|
import gzutil from "./api/gzutil";
|
||||||
import locale from "./api/locale";
|
import locale from "./api/locale";
|
||||||
import gzapi from "./api/apiutil";
|
import gzapi from "./api/gzapi";
|
||||||
import gzvalidate from "./api/gzvalidate";
|
import gzvalidate from "./api/gzvalidate";
|
||||||
import "@/assets/css/main.css";
|
import "@/assets/css/main.css";
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ Object.defineProperty(Vue.prototype, "$_", { value: lodash });
|
|||||||
Object.defineProperty(Vue.prototype, "$gzlocale", { value: locale });
|
Object.defineProperty(Vue.prototype, "$gzlocale", { value: locale });
|
||||||
Object.defineProperty(Vue.prototype, "$gzapi", { value: gzapi });
|
Object.defineProperty(Vue.prototype, "$gzapi", { value: gzapi });
|
||||||
Object.defineProperty(Vue.prototype, "$gzv", { value: gzvalidate });
|
Object.defineProperty(Vue.prototype, "$gzv", { value: gzvalidate });
|
||||||
Object.defineProperty(Vue.prototype, "$gzerror", {
|
Object.defineProperty(Vue.prototype, "$gzHandleFormError", {
|
||||||
value: errorHandler.handleFormError
|
value: errorHandler.handleFormError
|
||||||
});
|
});
|
||||||
Object.defineProperty(Vue.prototype, "$gzdevmode", {
|
Object.defineProperty(Vue.prototype, "$gzdevmode", {
|
||||||
|
|||||||
@@ -158,12 +158,13 @@ export default {
|
|||||||
"WidgetCustom15",
|
"WidgetCustom15",
|
||||||
"WidgetCustom16"
|
"WidgetCustom16"
|
||||||
];
|
];
|
||||||
|
var that = this;
|
||||||
this.$gzlocale
|
this.$gzlocale
|
||||||
.fetch(ltKeysRequired)
|
.fetch(ltKeysRequired)
|
||||||
.then(() => (this.formReady = true))
|
.then(() => (this.formReady = true))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
this.formReady = true;
|
this.formReady = true;
|
||||||
this.$gzerror(err);
|
that.$gzHandleFormError(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
@@ -174,7 +175,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
obj: {},
|
obj: {},
|
||||||
serverError: {},
|
serverError: {},
|
||||||
errorBoxMessage:null,
|
errorBoxMessage: null,
|
||||||
formReady: false
|
formReady: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -184,9 +185,15 @@ export default {
|
|||||||
},
|
},
|
||||||
getDataFromApi() {
|
getDataFromApi() {
|
||||||
var url = "Widget/" + this.$route.params.id;
|
var url = "Widget/" + this.$route.params.id;
|
||||||
this.$gzapi.get(url).then(res => {
|
var that = this;
|
||||||
this.obj = res.data;
|
this.$gzapi
|
||||||
});
|
.get(url)
|
||||||
|
.then(res => {
|
||||||
|
this.obj = res.data;
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
that.$gzHandleFormError(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
submit() {
|
submit() {
|
||||||
//check if form is valid, as far as I know this is the way you're supposed to do it and in testing it does not force all fields to revalidate individually
|
//check if form is valid, as far as I know this is the way you're supposed to do it and in testing it does not force all fields to revalidate individually
|
||||||
@@ -198,24 +205,26 @@ export default {
|
|||||||
this.$gzv.ClearServerErrors(this);
|
this.$gzv.ClearServerErrors(this);
|
||||||
//this.$gzutil.RemoveAllPropertiesFromObject(this.serverError);
|
//this.$gzutil.RemoveAllPropertiesFromObject(this.serverError);
|
||||||
|
|
||||||
this.$gzapi.upsert(url, this.obj).then(res => {
|
this.$gzapi
|
||||||
if (res.error) {
|
.upsert(url, this.obj)
|
||||||
that.serverError = res.error;
|
.then(res => {
|
||||||
that.$gzv.SetErrorBoxErrors(that);
|
if (res.error) {
|
||||||
} else {
|
that.serverError = res.error;
|
||||||
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
|
that.$gzv.SetErrorBoxErrors(that);
|
||||||
if (res.id) {
|
|
||||||
//Handle "post" of new record
|
|
||||||
that.obj = res.data;
|
|
||||||
} else {
|
} else {
|
||||||
//Handle "put" of an existing record
|
//Logic for detecting if a post or put: if id then it was a post, if no id then it was a put
|
||||||
that.obj.concurrencyToken = res.data.concurrencyToken;
|
if (res.id) {
|
||||||
|
//Handle "post" of new record
|
||||||
|
that.obj = res.data;
|
||||||
|
} else {
|
||||||
|
//Handle "put" of an existing record
|
||||||
|
that.obj.concurrencyToken = res.data.concurrencyToken;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
});
|
.catch(function(error) {
|
||||||
//In theory all exceptions should be handled by the gzapi methods, so we should not need to deal with this in the form very often if at all
|
that.$gzHandleFormError(error);
|
||||||
// .catch(function(error) {
|
});
|
||||||
// });
|
|
||||||
} else {
|
} else {
|
||||||
//say something so the user knows there is an issue
|
//say something so the user knows there is an issue
|
||||||
alert("STUB: You can't do that, there are broken rules");
|
alert("STUB: You can't do that, there are broken rules");
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export default {
|
|||||||
.then(() => (this.formReady = true))
|
.then(() => (this.formReady = true))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
this.formReady = true;
|
this.formReady = true;
|
||||||
this.$gzerror(err);
|
this.$gzHandleFormError(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export default {
|
|||||||
.then(() => (this.formReady = true))
|
.then(() => (this.formReady = true))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
this.formReady = true;
|
this.formReady = true;
|
||||||
this.$gzerror(err);
|
this.$gzHandleFormError(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|||||||
Reference in New Issue
Block a user