Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ajax.Request considers timeout/connection close to be a success. #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/prototype/ajax/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ Ajax.Request = Class.create(Ajax.Base, {
**/
success: function() {
var status = this.getStatus();
// status = 0 is also returned upon timeout and connection
// close
if (!status && ('' == this.transport.getAllResponseHeaders()))
return false;
return !status || (status >= 200 && status < 300) || status == 304;
},

Expand Down
26 changes: 26 additions & 0 deletions test/unit/ajax_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,31 @@ new Test.Unit.Runner({
} else {
this.info(message);
}
},

testReportConnectionBroken: function() {
if (this.isRunningFromRake) {
var successTriggered = false,
failureTriggered = false,
exceptionTriggered = false;

new Ajax.Request("/down", extendDefault({
onSuccess: function(transport) {
successTriggered = true;
}.bind(this),
onFailure: function(transport) {
failureTriggered = true;
}.bind(this),
onException: function() {
// onException will not trigger for asynchronous
// requests
exceptionTriggered = true;
}
}));

this.assertEqual(successTriggered, false, 'a request timeout is no success');
this.assertEqual(failureTriggered, true, 'a request timeout is a failure');
this.assertEqual(exceptionTriggered, true, 'a synchronous request timeout throws an exception');
}
}
});