This commit is contained in:
2019-04-08 21:15:14 +00:00
parent fda9dcddda
commit b758cdad9a
4 changed files with 37 additions and 14 deletions

View File

@@ -6,9 +6,9 @@ var devModeShowErrors = false;
////////////////////////////////////////////////////////
//
// Log and optionally display errors
//
function dealWithError(msg, displayToUser) {
// Localize, Log and optionally display errors
// return localized message in case caller needs it
function dealWithError(msg, form) {
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
@@ -16,9 +16,22 @@ function dealWithError(msg, displayToUser) {
msg = msg.replace("??", "");
}
store.commit("logItem", msg);
if (displayToUser || devModeShowErrors) {
if (devModeShowErrors) {
alert("~" + msg);
}
//If a form instance was provided (vue instance)
//then put the error into it
if (form) {
if (form.$gzdevmode()) {
//make sure appError is defined on data
if (!form.$_.has(form, "appError")) {
throw "DEV ERROR errorHandler::dealWithError -> appError seems to be missing from form's vue data object";
}
}
form.appError = msg;
form.$gzv.SetErrorBoxErrors(form);
}
}
export default {
developmentModeShowErrorsImmediately(showErrorsImmediately) {
@@ -63,12 +76,16 @@ export default {
}
dealWithError(msg);
},
handleFormError(err, displayToUser) {
//called inside forms when things go wrong but are handled
/////////////////////////////////////////////////
// Localize, log and return error
//
handleFormError(err, form) {
//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, displayToUser);
dealWithError(err.message, form);
} else {
dealWithError(err.toString(), displayToUser);
dealWithError(err.toString(), form);
}
}
};