[Dojo-interest] dealing with XHR error code

James Burke jburke at dojotoolkit.org
Sun Aug 26 05:37:41 UTC 2007


You could use the following (works for whatever handleAs value you
passed into the XHR call.

error: function(result, ioArgs){
    var parsedResult = dojo._contentHandlers[ioArgs.handleAs](ioArgs.xhr);
}

If you would like this to be more automatic/done by the interior Dojo
code, feel free to open a ticket at http://trac.dojotoolkit.org (use
guest/guest account).

James

On 8/25/07, Luke Saunders <luke.saunders.lists at googlemail.com> wrote:
> Normally when doing XHR, if the request is invalid (like if a field is
> missing or even if there's an incorrect password) I have the API respond
> with an error code (400 usually) and some JSON as the response body normally
> containing a reason for the error so the front end can deal with it nicely,
> like give the user a meaningful message.
>
> However, when using dojo.xhrGet() the response is just an Error object if an
> error response code is returned, the only way to get to the actual JSON
> response is to parse ioArgs.xhr.responseText which is horrible compared to
> just getting the JSON object as the response as is the case with a
> successful request.
>
> Have I got this right? What's the best way to handle this?
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
>
>


More information about the Dojo-interest mailing list