Change Error Message

Change Error Message

avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0

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

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin
    edited October 2014

    The i18n.error.system option can be used to customise that error message.

    Allan

  • avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0

    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?

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    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

  • avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0

    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

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    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:

    {
       "error": "Cannot delete. Must delete ... first"
    }
    

    And then Editor will display that in the form error message.

    See the client / server documentation for more information.

    Allan

  • avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0
    edited November 2014

    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

    {"error":"DBD::Pg::st execute failed: ERROR:  update or delete on table \"categories\" violates foreign key constraint \"parts_category_id_fkey\" on table \"parts\"\nDETAIL:  Key (id)=(36) is still referenced from table \"parts\".\n"}
    
  • avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0

    Updated using the correct markdown :)

    {"error":"DBD::Pg::st execute failed: ERROR: update or delete on table \"categories\" violates foreign key constraint \"parts_category_id_fkey\" on table \"parts\"\nDETAIL: Key (id)=(36) is still referenced from table \"parts\".\n"}
    
  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Interesting - that looks like it should work to me! Can you show me your client-side code please?

    Thanks,
    Allan

  • avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0

    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

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    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

  • avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0

    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

  • allanallan Posts: 61,667Questions: 1Answers: 10,096 Site admin

    Its the client-side Javascript code I want to look at, but not the server-side Perl code :-)

    Allan

  • avcarrilloavcarrillo Posts: 15Questions: 2Answers: 0

    I was able to resolve the issue by using the following code

        editor.on('submitError', function ( e, xhr, err, thrown, data ){
            data = JSON.parse(xhr.responseText);
            this.error(JSON.parse(xhr.responseText).error);
            return false;
        });
    
This discussion has been closed.