Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#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:
Blocked by: Blocking:

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 (3)

comment:1 Changed 8 years ago by dmethvin

Resolution: wontfix
Status: newclosed

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.

comment:2 Changed 7 years ago by jaubourg

Resolution: wontfixfixed

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 7 years 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

Note: See TracTickets for help on using tickets.