Kendo Grid DataSource error handler not firing

Viewed 26

Have a Kendo Read Call from JQuery as follows:

 var dataSource = new kendo.data.DataSource({
    error: function (e) {
       if (e.status === "error") {
           this.cancelChanges();
           showToast("Error Occurred", e.xhr.responseText, "exclamation-circle", "red");
           var grid = $('#grid').data('kendoGrid');
           grid.dataSource._data = self.formatData(grid.dataSource.data());
           grid.refresh();
       }
    },
    requestEnd: onRequestEnd,
    transport: {
        read: {
            type: "GET",
            dataType: "json",
            url: '/api/user/getall'
        },
        destroy: {
            url: function (data) {
                return "api/user/delete/" + data.RecordKey;
            },
            type: "delete",
            dataType: "json"
        },
        parameterMap: function (data, operation) {
            return kendo.stringify(data);
        }
    },

The server determines user unauthorized and returns the following Content

...

        return new ContentResult()
        {
            StatusCode = 401,
            Content = "No Access" 
        };

...

The errors blodk in the in the datasource does not fire? Not sure what I am missing.

1 Answers

Seems like the issue is with the parameterMap definition, specifically when the function is executed on a read operation

parameterMap: function (data, operation) {
        if (operation != "read") {
          return kendo.stringify(data);
        }
      }

With the above update and a mock 401 response the error event fires as expected - example.

Related