This is a migrated thread and some comments may be shown as answers.

Trapping grid errors correctly

1 Answer 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 28 Jun 2017, 11:36 PM

I have a grid on an MVC page, I have an error event as follows:

        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(false)                                          
            .PageSize(50)                                      
            .Events(events => events.Error("gridErrorHandler"))

My JavaScript function is something like:

function gridErrorHandler(e) {
   ... 
}

I have an MVC method (that returns ActionResult) that throws the following error when an error condition occurs:

return new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError, "Unexpected error");

My question is this. When my MVC method throws an exception, my JS error handler gets called. But, no matter what I try, I'm not able to get at the type of error it is. What exactly is the correct JS code that tells me a 500 error occurred, or a 401 (unauthorized) error occurred, etc.? 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 30 Jun 2017, 01:23 PM
Hi Randy,

If you are handling the exception you could pass it as a ModelState error as shown in the following help article:
As for the current approach, the error event argument could be used for retrieving the error message and the error code:
function gridErrorHandler(e) {
   e.errorThrown //the error message
   e.xhr.status // 500, 401, etc.
}

Hope this helps.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or