Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#7201 closed bug

Exception thrown by $.ajax.error callback cannot be caught by outer try...catch (for a synchronous request)

Reported by: cipinistor@… Owned by: cipinistor@…
Priority: low Milestone: 1.5
Component: ajax Version: 1.5
Keywords: Cc:
Blocked by: Blocking:

Description

Making a synchronous $.ajax request that completes with a server exception, an exception thrown inside the "error" callback cannot be caught by an outer try...catch.

That is because in 1.4.2 the result of the request is handled in an asynchronous manner (by attaching a handler to the xhr.onreadystatechange event, even for synchronous requests) thus making it impossible to catch an exception from the error callback.

A possible fix for this could be modifying this line:

var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {

into:

var onreadystatechange = function( isTimeout ) {

and after the onreadystatechange code block, this should be added:

if (s.async) {

xhr.onreadystatechange = onreadystatechange;

}

Change History (5)

comment:1 Changed 9 years ago by addyosmani

Component: unfiledajax
Owner: set to cipinistor@…
Priority: undecidedlow
Status: newpending

Please provide a valid test case that we can use to verify the behavior described in your ticket.

comment:2 Changed 9 years ago by snover

Milestone: 1.4.41.4.5

Retargeting due to severity of regressions in 1.4.3.

comment:3 Changed 9 years ago by trac-o-bot

Status: pendingclosed

Automatically closed due to 14 days of inactivity.

comment:14 Changed 9 years ago by john

Version: 1.4.21.5

There wasn't a 1.4.5 release, was actually 1.5.

comment:15 Changed 9 years ago by john

Milestone: 1.4.51.5

There was no 1.4.5 release, was actually 1.5.

Note: See TracTickets for help on using tickets.