Change Error Message
Change Error Message
When trying to delete an entry using ajax override, I get the following message in the editor window
"A system error has occurred (More information)."
I know what the cause is, as the xhr is returning 400 Bad Request, with the reason why. I want to change the error message from the default non descriptive message to something more meaningful. How do I change the errorCallBack to show my message?
if (data.action == "remove") {
$.ajax({
type : "DELETE",
url : api + data.id,
dataType : "json",
success : function(json) {
successCallback(json);
},
error : function(xhr, error, thrown) {
errorCallback(xhr, error, thrown);
}
});
}
Thank you
Answers
The
i18n.error.system
option can be used to customise that error message.Allan
Hi Allan,
Thank you for the quick response.
This appears to be a static response. Is it possible to change the error based on the Ajax response?
You could use
error()
in the callback, however, that specific error is something that the user should never see since it represents a significant problem with the JSON formatting.Allan
The issue is that the ajax response is stating there is an issue because in this case I am trying to delete a row that is dependent on another table that still exists. I want to let the user know he has to remove that other dependency before he can delete this row. I have been unable to figure out how to use error() in the errorCallback.
Do you have an example that would apply here?
error : function(xhr, error, thrown) {
errorCallback(xhr, error, thrown);
}
Thank you
I would suggest replying with valid JSON rather than entering into the Ajax error handler, since this sis a known state and you know what the error is. Have the server reply with:
And then Editor will display that in the form error message.
See the client / server documentation for more information.
Allan
The server is responding with an error in this format, but it is not being displayed on the delete form.
this is what is being returned from the server
Updated using the correct markdown :)
Interesting - that looks like it should work to me! Can you show me your client-side code please?
Thanks,
Allan
I don't have access to the client side code. Also it's written in perl. I pulled that line directly from the header in chrome.
Thank you for your time on this
The client-side code must be downloaded to your browser in order for it to run. I'm not looking for the server-side code (Perl in this case, based on what you say), but rather the Javascript.
Allan
Total brain fart on that last comment. I meant to say, I don't have access to the server side code. I'm working with the API. I can request it, but I know it's works off of perl, mojolicious, and postgres. You would have to replicate the environment/db in order to get any results.
I can request the source if you want to go this route. any other way I can get you the information you are looking for?
Thank you Allan
Its the client-side Javascript code I want to look at, but not the server-side Perl code :-)
Allan
I was able to resolve the issue by using the following code