Grid.data.load 403 error catch


#1

How to recognize 403 error when using data.load?
I tried then and catch but catch returns something like below when url returns 403. It does not matter if it is returned as classic http error or as json.

Error: [object Object]
    dhxError /lib/dhtmlx/suite.min.js:12
    u /lib/dhtmlx/suite.min.js:12
    fire /lib/dhtmlx/suite.min.js:12
    fire /lib/dhtmlx/suite.min.js:12
    loadData /lib/dhtmlx/suite.min.js:21
    promise callback*i</</e.prototype.load /lib/dhtmlx/suite.min.js:21
    load /lib/dhtmlx/suite.min.js:12
    initGekkon /lib/new_interface.js:336
    appInit /lib/new_interface.js:75
    onload /:1

#2

I’m using the below code to catch a 404 error, but it should work the same for 403.

dhx.ajax.get(url).then(function(data){
    // stuff here
}).catch(function(error){
    if (error.status && parseInt(error.status) === 404){
        // stuff here on a 404 error
    }
});

If I recall, I struggled with the same thing as you for a while, where I couldn’t expose the members of the object through a simple console.log(error), but I happened to see something about the “status” member in some other forum post while looking to resolve a different issue.


#3

Your solution is working perfectly for Ajax helper, so when you call

dhx.ajax.get/post

it will be as you described.

However when you do:

grid.data.load([your_url]).then(function(response) { //your code if needed}).catch(function(error) { console.log(error.status) });

this will return undefined in console.


#4

Hello.

Please, try to to use the loadError event:
https://docs.dhtmlx.com/suite/data_collection__api__loaderror_event.html