This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user