Trapping grid errors correctly

2 posts, 0 answers
  1. Randy
    Randy avatar
    75 posts
    Member since:
    Jul 2009

    Posted 28 Jun 2017 Link to this post

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

            .DataSource(dataSource => dataSource
                .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.? 

  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 30 Jun 2017 Link to this post

    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.

    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.
Back to Top