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

Handling datasource exceptions

9 Answers 1250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 07 Mar 2018, 02:27 PM

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;
}

 

 

9 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 09 Mar 2018, 01:07 PM
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.
0
Alex
Top achievements
Rank 1
answered on 09 Mar 2018, 01:14 PM

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?

0
Viktor Tachev
Telerik team
answered on 09 Mar 2018, 01:25 PM
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.
0
Alex
Top achievements
Rank 1
answered on 09 Mar 2018, 01:42 PM
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.
0
Viktor Tachev
Telerik team
answered on 12 Mar 2018, 09:22 AM
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.
0
Alex
Top achievements
Rank 1
answered on 12 Mar 2018, 03:00 PM
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.
0
Viktor Tachev
Telerik team
answered on 13 Mar 2018, 01:23 PM
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.
0
Dan
Top achievements
Rank 1
Veteran
answered on 30 Jul 2020, 09:20 PM

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

0
Anton Mironov
Telerik team
answered on 04 Aug 2020, 04:21 PM

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

Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Alex
Top achievements
Rank 1
Dan
Top achievements
Rank 1
Veteran
Anton Mironov
Telerik team
Share this question
or