Ticket #11151 (closed enhancement: fixed)
jQuery AJAX Error Response Body Parsing
| Reported by: | mako281@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
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.
Change History
comment:1 Changed 17 months ago by dmethvin
- Status changed from new to closed
- Resolution set to wontfix
comment:2 Changed 4 months ago by jaubourg
- Resolution changed from wontfix to fixed
Fixes #11151, #13388. Minor refactor of response conversion and when/where responseXXX fields are set on the jqXHR. Close gh-1164. Changeset: 69b3d5ce0f081d3f113b2917495f35df160f8522
comment:3 Changed 4 months ago by jaubourg
Fixes #11151, #13388. Minor refactor of response conversion and when/where responseXXX fields are set on the jqXHR. Close gh-1164.
(Cherry-picked from 69b3d5ce0f081d3f113b2917495f35df160f8522)
Changeset: eebc77849cebd9a69025996939f930cbf9b1bae1
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Considering this is an edge case, I wouldn't be in favor of adding bytes for it. You can always call $.parseJSON yourself, which puts you in control of which error you prefer to process.