Bug Tracker

Modify

Ticket #7201 (closed bug)

Opened 3 years ago

Last modified 2 years ago

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

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

comment:1 Changed 3 years ago by addyosmani

  • Owner set to cipinistor@…
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to ajax

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

comment:2 Changed 3 years ago by snover

  • Milestone changed from 1.4.4 to 1.4.5

Retargeting due to severity of regressions in 1.4.3.

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

  • Status changed from pending to closed

Automatically closed due to 14 days of inactivity.

comment:14 Changed 2 years ago by john

  • Version changed from 1.4.2 to 1.5

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

comment:15 Changed 2 years ago by john

  • Milestone changed from 1.4.5 to 1.5

There was no 1.4.5 release, was actually 1.5.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.