This commit is contained in:
2019-05-02 19:46:34 +00:00
parent 60d1fb82fe
commit 640c6ef095
20 changed files with 400 additions and 271 deletions

View File

@@ -1,14 +1,14 @@
/* Xeslint-disable */
import store from "../store";
import locale from "./locale";
import gzevent from "./eventbus";
var devModeShowErrors = false;
////////////////////////////////////////////////////////
//
// Localize, Log and optionally display errors
// return localized message in case caller needs it
function dealWithError(msg, form) {
function dealWithError(msg, vm) {
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
@@ -17,20 +17,24 @@ function dealWithError(msg, form) {
}
store.commit("logItem", msg);
if (devModeShowErrors) {
alert("~" + msg);
gzevent.$emit(
"notify-error",
"DEV ERROR errorHandler::devShowUnknownError - unexpected error: \r\n" +
msg
);
}
//If a form instance was provided (vue instance)
//then put the error into it
if (form) {
if (form.$gzdevmode()) {
if (vm) {
if (vm.$gzdevmode()) {
//make sure formState.appError is defined on data
if (!form.$_.has(form, "formState.appError")) {
if (!vm.$_.has(vm, "formState.appError")) {
throw "DEV ERROR errorHandler::dealWithError -> formState.appError seems to be missing from form's vue data object";
}
}
form.formState.appError = msg;
form.$gzform.setErrorBoxErrors(form);
vm.formState.appError = msg;
vm.$gzform.setErrorBoxErrors(vm);
}
}
export default {
@@ -79,13 +83,13 @@ export default {
/////////////////////////////////////////////////
// Localize, log and return error
//
handleFormError(err, form) {
handleFormError(err, vm) {
//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, form);
dealWithError(err.message, vm);
} else {
dealWithError(err.toString(), form);
dealWithError(err.toString(), vm);
}
}
};