Send back server side error on create/edit/delete

Send back server side error on create/edit/delete

eon_nordic_oneeon_nordic_one Posts: 5Questions: 0Answers: 0
edited February 2014 in Editor
When something goes wrong on the server and I set the response status to 400 the editor client will give me the standard "An error has occurred - Please contact the system administrator" which is fine. But in some cases I would like to send back an error message as json. I can see that there is the sError field in the examples. I can't figure out how to use it though to replace the standard error message?

regards

/h

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    I think you want to send back the `error` parameter rather than `sError` which is a DataTables parameter: https://editor.datatables.net/server/#error

    However, I suspect that if you are returning a 400 error, what you will need to do is use the `onSubmitError` event handler ( https://editor.datatables.net/api/#onSubmitError ) and the `error()` API method to show your message, since Editor will show a generic (although configurable through the i18n options) error message when jQuery falls into its error handler.

    Allan
  • eon_nordic_oneeon_nordic_one Posts: 5Questions: 0Answers: 0
    Hi!

    Ok but the onSubmitError doesn't contain a JSON object and that's where my message is? Or am I missing something?

    /Harald
  • eon_nordic_oneeon_nordic_one Posts: 5Questions: 0Answers: 0
    Ok found out that xhr.responseText gives me the json..
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Yup - you can use $.parseJSON to convert to JSON from there.

    Allan
This discussion has been closed.