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

RequestEnd Event - Can I detect if an error occurred during the event?

3 Answers 587 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 15 Nov 2019, 07:38 PM

In my MVC grid code, I have the following:

.DataSource(dataSource => dataSource
   .Ajax()
   .Batch(false)
   .PageSize(25)
   .Events(events => events.Error("gridErrorHandler")) 
   .Events(events => events.RequestEnd("onRequestEndCertification(\"employeeCertificationGrid\")"))
   ...
)

As you can see, I have both an error handler and a RequestEnd handler. However, in my RequestEnd handler function, I would like to be able to check for any error which may have occurred during the event, before I proceed. I cannot find a way, from within the RequestEnd handler, to detect if any error occurred in the operation. Is there a way?

I did notice an e.response.Error object but it never seems to contain any information.

 

 

 


 

 

3 Answers, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 18 Nov 2019, 04:09 PM

Hi Randy,

The attached project demonstrates a Gird with DataSource that has both the error and requestEnd events defined. If you open the browser console you will see the order in which the two events have been called - the Error event is called after the requestEnd event. 

By pointing the above event triggering sequence I am trying to say that you can rely on the Error event to check if there were any errors in the request. If the request is without errors, the Error event won't be fired. To check my word, in the attached project rename the Read method of the Grid's datasource to Orders_Read and you will see that only the event handler of the requestEnd event will be printed in the console. 

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Randy
Top achievements
Rank 1
answered on 18 Nov 2019, 06:00 PM

Hi Peter - I'm not sure how your response to my question helps me unless you are trying to tell me that there is no way I can know, in the requestEnd event, that any error actually occurred, because the error event fires after the requestEnd event

I already knew I could rely on the error event to check for errors, because that's what the error event is designed to do. However, I would like to be able to determine an error occurred in the requestEnd event because what I do in the event will be different if an error occurred vs no error occurring.

0
Petar
Telerik team
answered on 20 Nov 2019, 01:43 PM

Hi Randy,

The only way I could suggest for tracking if there is an error with the request inside the requestEnd event is to check if the response property of the event handler is defined or not. If the property is undefined then there has been an error in the request. 

The modified version of the project I previously sent you demonstrates my suggestion. If you change the returned result in the controller you will see the difference of the response property value. 

If you need to track the error type, this could be done in the Error event only. If further logic should be executed based on an error type then an approach with global variables getting the needed values from the error event could be used.

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Petar
Telerik team
Randy
Top achievements
Rank 1
Share this question
or