Handling datasource exceptions

10 posts, 0 answers
  1. Alex
    Alex avatar
    48 posts
    Member since:
    Jun 2011

    Posted 07 Mar 2018 Link to this post

    How do I handle an exception that occurs when generating the data to be sent to the grid?  I've seen an example of a call to a Javascript "error_handler" method.  Is that my only option?

    <kendo-grid name="grid">
        <datasource type="DataSourceTagHelperType.Ajax" on-error="Error">
            <transport>
                <read url="Home/GetOrgs" />
            </transport>
        </datasource>
        ...
    </kendo-grid>

     

    public IActionResult GetOrgs([DataSourceRequest] DataSourceRequest request)
    {
        int x = 0; int r = 10 / x;
    }

     

     

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2499 posts

    Posted 09 Mar 2018 Link to this post

    Hello Alex,

    By default when a server-side error occurs the relevant information for it would be returned to the client in the Errors field of the response. If you would like to implement additional custom logic in case of an error or prompt the user the recommended option is to use the error event


    Regards,
    Viktor Tachev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Alex
    Alex avatar
    48 posts
    Member since:
    Jun 2011

    Posted 09 Mar 2018 in reply to Viktor Tachev Link to this post

    It would be nice to see a failure, but all that I see is an empty grid (no errors).  Can you try to reproduce this? 

    So if I want to handle the error I would need to handle it through Javascript only?

  4. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2499 posts

    Posted 09 Mar 2018 Link to this post

    Hi Alex,

    In order for the Grid to display data the response from the Read Action should be in a format that is expected by the DataSource. Thus, make sure that you are calling ToDataSourceRedult to the data returned from the Read ActionMethod. 

    Please check out the Controller tab in the example below that outlines how a Read action would look:



    Regards,
    Viktor Tachev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Alex
    Alex avatar
    48 posts
    Member since:
    Jun 2011

    Posted 09 Mar 2018 in reply to Viktor Tachev Link to this post

    I can't say that your response is valid in any way.  As you can see in my code sample, I'm trying to get the application to throw an exception, not format data correctly.  I have no issues with displaying data in the way that it was intended.
  6. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2499 posts

    Posted 12 Mar 2018 Link to this post

    Hi Alex,

    The Read action would be operating with data, thus it would return errors that are related to data operations (e.g. database error, db connection problem, etc.). Such errors would be added to the ModelState and returned by the server-side action. Please check out the article below (step7 and step8) that outlines how to return the ModelState with the respective data. 


    For handling general exceptions in the application I would suggest using the approach described in the following article:




    Regards,
    Viktor Tachev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. Alex
    Alex avatar
    48 posts
    Member since:
    Jun 2011

    Posted 12 Mar 2018 in reply to Viktor Tachev Link to this post

    Thank you for the additional information.  I believe, however, the answer to my question is the following: If you are binding the grid using the ajax transport,the call tot he databind happens async to the control flow and thus any error will not be displayed.  Therefore, you must detect and handle the error using on-error Javascript function rather than being able to control any flow through the server-side code.
  8. Viktor Tachev
    Admin
    Viktor Tachev avatar
    2499 posts

    Posted 13 Mar 2018 Link to this post

    Hi Alex,

    If you would like to customize the returned result you can define the DataSourceResult manually and specify the Errors field with the relevant information. The example below illustrates how to specify the DataSourceResult fields manually. 



    Regards,
    Viktor Tachev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  9. Dan
    Dan avatar
    15 posts
    Member since:
    Dec 2017

    Posted 30 Jul 2020 in reply to Viktor Tachev Link to this post

    in the link referenced by

    "The Read action would be operating with data, thus it would return errors that are related to data operations (e.g. database error, db connection problem, etc.). Such errors would be added to the ModelState and returned by the server-side action. Please check out the article below (step7 and step8) that outlines how to return the ModelState with the respective data. "

    I don't see a step 7 and step 8.  The link doesn't seem to be related at all to what you are referencing.  Can you provide an updated link?

     

    thanks

  10. Anton Mironov
    Admin
    Anton Mironov avatar
    167 posts

    Posted 04 Aug 2020 Link to this post

    Hi, Dan,

    Thank you for this question.

    Our official documentation has been updated and extended a couple of times for the last two years. Find the appropriate article for handling ModelState errors here:

    1. For inline editing:

    2. Handling Server-side validation errors(blog article):

    I hope this information helps.

    Kind Regards,
    Anton Mironov
    Progress Telerik

Back to Top