Server Side Error shown

Server Side Error shown

Andreas S.Andreas S. Posts: 208Questions: 74Answers: 4

How can i show a server-side error that send with json to the datatables. The error looks like this format:

{
    "type": "error",
    "icon": "fa fa-exclamation-triangle",
    "title": "404, Not Found",
    "text": "\r\n\t\t\t<p class=\"margin-left-5\">\r\n\t\t\t\t<span class=\"text-black weight-600\">Time:<\/span> 17.December 2017 17:37:36<br \/>\r\n\t\t\t\t<span class=\"text-black weight-600\">API:<\/span> \/meet\/88a9135f-7f17-467b-ad9b-7b7b8037a964\/clubs<br \/>\r\n\t\t\t\t<span class=\"text-black weight-600\">Message:<\/span><br \/>The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.\r\n\t\t\t<\/p>"
}

i read something with this:

$.fn.dataTable.ext.errMode = 'throw';

        evlist.on(
            'error.dt', function( e, settings, techNote, message ) {
                console.log(e);
            } );

but i can not read the json to display it.

Andreas

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Try changing your errMode to be none. The issue is that unless you try / catch the thrown error, the next code won't execute.

    Allan

  • Andreas S.Andreas S. Posts: 208Questions: 74Answers: 4

    I changed this, but it looks like that the event.on are not called The server send the error in the json format. I did not see something in the console.log.
    I hope i understand it right, that dataTables makes an error if the json Data did not have the correct format for create a table?

    Andreas

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Ah - I think I understand. The server is returning valid JSON, but it isn't in the format that DataTables is expecting (i.e. you don't have an empty array of data). When there isn't an empty array of data, DataTables will indeed throw an error and that won't be caught by the error handler.

    What you need to do is add an empty array at the point where DataTables would be attempting to read the data from - e.g. "data": [] perhaps.

    Allan

  • Andreas S.Andreas S. Posts: 208Questions: 74Answers: 4

    Did i understand it right. I should send this to the dataTable

    {
        "data": []
        "type": "error",
        "icon": "fa fa-exclamation-triangle",
        "title": "404, Not Found",
        "text": "\r\n\t\t\t<p class=\"margin-left-5\">\r\n\t\t\t\t<span class=\"text-black weight-600\">Time:<\/span> 17.December 2017 17:37:36<br \/>\r\n\t\t\t\t<span class=\"text-black weight-600\">API:<\/span> \/meet\/88a9135f-7f17-467b-ad9b-7b7b8037a964\/clubs<br \/>\r\n\t\t\t\t<span class=\"text-black weight-600\">Message:<\/span><br \/>The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.\r\n\t\t\t<\/p>"
    }
    

    Andreas

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yes. Assuming you aren't using ajax.dataSrc, then that should stop the length error message being shown. The table will still show nothing.

    If I've misunderstood, can you link to the page so i can check it out please?

    Thanks,
    Allan

  • Andreas S.Andreas S. Posts: 208Questions: 74Answers: 4

    I use the ajax.dataSrc. I replace the data with my dataSrc name.
    With this extra field in Json, dataTable did not give any error out. it build an empty table.
    However in the Json file there are some more Information the should popup.
    I use pNotify pop up the error, I send you the information where you can try in a PN.

    Andreas

This discussion has been closed.