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

Error Handling

13 Answers 2249 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luis Esquivel
Top achievements
Rank 1
Luis Esquivel asked on 15 Feb 2012, 02:12 AM
Hello,
  I want to know how to manage errors from web service.
  I have a response like this (my implementation is json format):

<Products>
  <OperationTag>
   <ErrorCode>000001</ErrorCode>
  </OperationTag>
  <ProductsBag>
   <Product>
    <ID>001</ID>
   </Product>
   <Product>
    <ID>002</ID>
   </Product>
  </ProductsBag>
</Products>

So, if ErrorCode has a value it was an error and ProductsBag will be empty.

Regards.

13 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 Feb 2012, 05:48 PM
Hi Luis,

In order to notify the DataSource, that an error occurred during the request execution the response should  return an error HTTP status code. This will trigger the error handler and raise the DataSource error event.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Carl
Top achievements
Rank 1
answered on 08 Mar 2012, 04:40 PM
Hi Rosen,

Could you please show how I access the error codes directly?  I'm using MVC4 WebApi and I'd like to handle errors based upon the HTTP status codes I return.

Thanks!
0
Rosen
Telerik team
answered on 09 Mar 2012, 08:43 AM
Hello Carl,

Did you mean how to access the status code within the DataSource error handler? If this is the case you may access it similar to the following:

var dataSource = new kendo.data.DataSource({
    error: function(e) {
        var xhr = e[0];
        var statusCode = e[1];
        var  errorThrown = e[2];
    }
});

However, note that with the Q1 2012 release this will be changed to the following format:

var dataSource = new kendo.data.DataSource({
    error: function(e) {
        var xhr = e.xhr;
        var statusCode = e.status;
        var  errorThrown = e.errorThrown;
    }
});

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Carl
Top achievements
Rank 1
answered on 09 Mar 2012, 09:31 PM
Yes, that's what I meant.  Thanks, I will give that a go!  :)
0
Carl
Top achievements
Rank 1
answered on 12 Mar 2012, 03:17 AM
Hi,

That has worked fine for me.  However, is it possible to get the HttpStatusCode even if there wasn't an error?  I can't find out where it would be exposed and there doesn't seem to be a success event?

Thanks!
0
Rosen
Telerik team
answered on 12 Mar 2012, 08:57 AM
Hi Carl,

There is no way to obtain the status code if the request is successful, as this is not applicable in the context of the DataSource component. This is also the reason there is no success event. The DataSource's change event has similar semantics as the success event  in the context of a DataSource.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Carl
Top achievements
Rank 1
answered on 12 Mar 2012, 07:22 PM
Hi Rosen,

Thanks for your reply.  I managed to find an example, it allows me to capture the HttpStatusCode.

http://www.kendoui.com/forums/framework/data-source/datasource-success-event.aspx
http://jsfiddle.net/rusev/tLFTH/

I'm returning extra header information along with custom statuses that need handling in my responses.
0
Engifaar
Top achievements
Rank 1
answered on 04 Jul 2012, 12:19 PM
Hello,

I am using Kendo datasource with RESTFUL WCF Service. It is working fine with every aspect. Now i want to trace Service status(Open /Closed) and want to display user friendly error message such as "Server is temporarily down!!"
Can anyone plz helk me out...

Thank you,
Deepak
0
Jacques
Top achievements
Rank 2
answered on 17 Sep 2013, 08:57 AM
how did you go about adding adding and extracting additional header data?
0
Rosen
Telerik team
answered on 19 Sep 2013, 10:54 AM
Hi,

You can use the schema error option to specify where the custom error is located in the response. If this response field is not empty DataSource error event will be raised.

Another approach is shown in the sample shown the in Carl's last post.

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 03 Jul 2015, 02:15 PM

For the dataSource error event...

please explain what kind of object e.errorThrown is (what properties, etc.).  When will it be present?  ...WITH e.xhr or only if e.xhr is not present?

Error-handling is important to me and your docs are very vague.

0
Rosen
Telerik team
answered on 06 Jul 2015, 07:36 AM

Hello Curt,

With the default implementation of the remote transport, the arguments of the error event are provided by the jQuery ajax error event. Therefore, you may take a look at the jQuery ajax documentation of error event for more information on the matter. The following is what it states about the error event:

  • error
    Type: FunctionjqXHR jqXHR, String textStatus, String errorThrown )
    A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout""error""abort", and "parsererror". When an HTTP error occurs, errorThrownreceives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn.Note: This handler is not called for cross-domain script and cross-domain JSONP requests. This is anAjax Event.

 

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Curt Rabon
Top achievements
Rank 1
Veteran
answered on 06 Jul 2015, 01:43 PM
Thank you Rosen for letting me know that; it is helpful and now I can plan accordingly.
Tags
Grid
Asked by
Luis Esquivel
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Carl
Top achievements
Rank 1
Engifaar
Top achievements
Rank 1
Jacques
Top achievements
Rank 2
Curt Rabon
Top achievements
Rank 1
Veteran
Share this question
or