Ticket #11151 (closed enhancement: fixed)
jQuery AJAX Error Response Body Parsing
|Reported by:||mako281@…||Owned by:|
I use jQuery with REST APIs and sometimes errors are reported via HTTP, with codes like 403 to indicate validation errors and whatnot.
As of now, jQuery will not even attempt to parse the response bodies if the status code is in the error code ranges. It would be nice if the response body could be parsed before getting passed off to the handler. (or perhaps if the ajaxConvert function could be exposed via jqXHR so we have access to that same conversion power in our error handlers)
I also understand one other scenario: an HTTP error occurs, and then attempts to parse are unsuccessful, leading to a parser error. (then jQuery would have 2 different errors it has to choose between) There could probably be different catch logic for error conditions than for normal conditions, but that would probably just leave an ugly empty catch block.
If ajaxConvert is exposed to the jqXHR object, then I could just use ajaxPrefilter or ajaxSetup to plant my own error handler that automatically parses the body. I wouldn't even mind hacking on the source some and submitting a pull request for review.