Skip to main content

Bug Tracker

Side navigation

#11151 closed enhancement (fixed)

Opened January 10, 2012 04:10PM UTC

Closed January 11, 2012 03:39PM UTC

Last modified February 28, 2013 08:01PM UTC

jQuery AJAX Error Response Body Parsing

Reported by: mako281@gmail.com 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.

Attachments (0)
Change History (3)

Changed January 11, 2012 03:39PM UTC by dmethvin comment:1

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.

Changed February 28, 2013 07:51PM UTC by jaubourg comment:2

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

Changed February 28, 2013 08:01PM UTC by jaubourg comment:3

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