Error Handling

14 posts, 0 answers
  1. Luis Esquivel
    Luis Esquivel avatar
    1 posts
    Member since:
    Oct 2004

    Posted 14 Feb 2012 Link to this post

    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.

  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 17 Feb 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Carl
    Carl avatar
    15 posts
    Member since:
    Nov 2010

    Posted 08 Mar 2012 Link to this post

    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!
  5. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 09 Mar 2012 Link to this post

    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!
  6. Carl
    Carl avatar
    15 posts
    Member since:
    Nov 2010

    Posted 09 Mar 2012 Link to this post

    Yes, that's what I meant.  Thanks, I will give that a go!  :)
  7. Carl
    Carl avatar
    15 posts
    Member since:
    Nov 2010

    Posted 11 Mar 2012 Link to this post

    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!
  8. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 12 Mar 2012 Link to this post

    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!
  9. Carl
    Carl avatar
    15 posts
    Member since:
    Nov 2010

    Posted 12 Mar 2012 Link to this post

    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.
  10. Engifaar
    Engifaar avatar
    15 posts
    Member since:
    May 2012

    Posted 04 Jul 2012 Link to this post

    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
  11. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 17 Sep 2013 Link to this post

    how did you go about adding adding and extracting additional header data?
  12. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 19 Sep 2013 Link to this post

    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!
  13. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 03 Jul 2015 Link to this post

    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.

  14. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 06 Jul 2015 Link to this post

    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!
     
  15. Curt Rabon
    Curt Rabon avatar
    45 posts
    Member since:
    Dec 2008

    Posted 06 Jul 2015 in reply to Rosen Link to this post

    Thank you Rosen for letting me know that; it is helpful and now I can plan accordingly.
Back to Top
Kendo UI is VS 2017 Ready