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

@@ -28,6 +28,7 @@ ISSUE: need to display multiple types of messages, best way to do that??
- Application errors
- Make them show with the server error box, rejig it as a generic error box
- App errors don't need to survive page reload or api call, if they are that serious then they would be notifications instead
- clearing server errors does not necessarily clear message box errors?
- Notifications, stuff that you want to know is there and can go and look at but isn't urgent enough to put in the users face
- Used for notification system, non-urgent system messages, direct messages from users etc, anything that isn't immediately important
- This seems like an application wide thing so maybe a bell icon that takes to another area of the program, or opens a div at the top or bottom of the page??

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

View File

@@ -272,7 +272,7 @@ export default {
// SERVER ERRORS
// Process and return server errors if any for form and field specified
ServerErrors(v, ref) {
//CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDE DATA ATTRIBUTES ETC
//CHECK PREREQUISITES IN DEV MODE TO ENSURE FORM ISN"T MISSING NEEDED DATA ATTRIBUTES ETC
if (v.$gzdevmode()) {
//make sure serverErrors is defined on data
if (!v.$_.has(v, "serverError")) {

View File

@@ -176,7 +176,7 @@ export default {
obj: {},
serverError: {},
errorBoxMessage: null,
appError:null,
appError: null,
formReady: false
};
},
@@ -187,14 +187,19 @@ export default {
getDataFromApi() {
var url = "Widget/" + this.$route.params.id;
var that = this;
this.$gzv.DeleteAllErrorBoxErrors(this);
this.$gzv.DeleteAllErrorBoxErrors(this);
this.$gzapi
.get(url)
.then(res => {
this.obj = res.data;
if (res.error) {
that.serverError = res.error;
that.$gzv.SetErrorBoxErrors(that);
} else {
that.obj = res.data;
}
})
.catch(function(error) {
that.$gzHandleFormError(error, true);
that.$gzHandleFormError(error, that);
});
},
submit() {
@@ -225,7 +230,7 @@ export default {
}
})
.catch(function(error) {
that.$gzHandleFormError(error, true);
that.$gzHandleFormError(error, that);
});
}
} //end of submit()