#1268 new
Steffen Luypaert

onFailure for Ajax.Responders.register does not work when an exception is catched

Reported by Steffen Luypaert | July 20th, 2011 @ 11:02 AM

In both prototype 1.6 and 1.7, there are the following lines for executing onSucces and onFailure functions that were supplied to Ajax.Responders.register:

try {
(this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON); Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON); } catch (e) { this.dispatchException(e); }

In the project I am working on, it is possible that the first line of the try block throws an exception that is catched by the catch block(we are building a framework, so it is not possible to prevent every possible exception there from happening). It is necessary to do something when this happens. Hence, I supplied an onFailure function. However, the onFailure is never called, since the actual dispatch to the onFailure would only occur if no exception is thrown.

We changed these prototype.js lines to the following for our project:

try {
(this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON); Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON); } catch (e) { this.dispatchException(e); Ajax.Responders.dispatch('onFailure', this, response, response.headerJSON); }

This way, when an exception is thrown, onFailure is still called, which should be the expected behaviour in a case like this I think.

Is the extra line something worth including in the standard prototype version, or is there a reason not to?

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Pages