Opened 14 years ago

Closed 14 years ago

#4295 closed enhancement (wontfix)

Passing response body to error handler when dealing with XHR error code

Reported by: guest Owned by: James Burke
Priority: high Milestone: 1.0
Component: General Version: 0.9
Keywords: xhr io json Cc:
Blocked By: Blocking:


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.

I propose that Dojo return the response body to the error handler as whatever was specified with 'handleAs' rather than forcing the handler to parse it manually from the xmlhttprequest object.

Change History (2)

comment:1 Changed 14 years ago by James Burke

Milestone: 1.0
Owner: changed from anonymous to James Burke

comment:2 Changed 14 years ago by James Burke

Resolution: wontfix
Status: newclosed

I agree this is awkward to do. I think the best option is to do the following:

Override dojo.d._isDocumentOk() (defined as d._isDocumentOk in dojo/_base/_loader/hostenv_browser.js), to return an OK for the HTTP status codes you consider as valid responses.

Otherwise, it gets messy with the API if we try to modify the load/error callbacks. We would need to change the API, not really an option for 1.0. Marking this as wontfix, with the suggestion of overriding dojo._isDocumentOk().

Note: See TracTickets for help on using tickets.