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

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!
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


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!
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

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.

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

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.
Rosen
Telerik

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.
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:
-
errorA 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,errorThrown
receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, theerror
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
