Editor.ajax.error doesn't catch http errors i.e. 401 etc.

Editor.ajax.error doesn't catch http errors i.e. 401 etc.

VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0
edited November 2015 in Editor

I try to catch 401/403 error in Editor on delete but it seems it doesn't work ...

See console at https://datatbl.herokuapp.com/users

Everything works fine with basic grid. On Tab-3 I return 401 on

ajax: { url: 'users.json', error: function (res) { console.log('Tab-3.Status: ' + res.status); }}

and the error-event is triggered.

On Tab-1 I use Editor and return 401 on delete, BUT neither datatable nor editor did not catch the error-event.

BTW: Also doesn't work (:

$.fn.dataTable.ext.errMode = function ( settings, helpPage, message ) { console.log('$.fn.dataTable.ext.errMode: '+message); };

Could anyone help me?

This question has an accepted answers - jump to answer

Answers

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

    I'm not entirely sure I understand the issue, or perhaps more specifically what you want to do. You want to handle the 401 return using some custom code? If so, use the statusCode option of the $.ajax object - which is basically all that ajax is and specify your custom function for a 401 return.

    Allan

  • VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0
    edited November 2015

    Hi Allan,

    I've simplified the example. The problem is that Editor's ajax doesn't detect HTTP-errors.

    How to reproduce:

    1. Go to https://datatbl.herokuapp.com/err401

    2. On the first retrieve I return 401 error and Datatable detects it fine - we see an alert.

    3. Create a new row and then delete it. On delete I also return 401 error and expect to see an alert as on step 2, but nothing happens.

    BR,
    Vyacheslav

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

    Thanks for the link - the issue is that the error property needs to be part of the Ajax object used. Since you have it broken into three crud components in Editor, it needs to be in those objects - e.g.:

    create: { type: 'POST',   url: 'users', error: function(res) {...} },
    

    I would add a warning about defining your own error option - it will override the Editor default and thus Editor will not be able to trigger any events. I would suggest using submitError rather than defining the error option.

    Allan

  • VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0

    Thank you for the clarification!

    submitError works perfect!

This discussion has been closed.