Skip to content

Commit

Permalink
detect aborted requests and don't panic. References bug 706
Browse files Browse the repository at this point in the history
The cause of bug 706 seems to be our own aborted requests,
mis-detected as XHR failures.

But there are other bad things that are still possible. User can abort
request by pressing Escape. And it seems there's no portable way to
distinguish that from not responding server.

Signed-off-by: Matt Ingenthron <ingenthr@cep.net>
  • Loading branch information
Aliaksey Kandratsenka authored and ingenthr committed Mar 10, 2010
1 parent bea8ee4 commit 752aed8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
8 changes: 8 additions & 0 deletions deps/menelaus/priv/js/app.js
Expand Up @@ -171,6 +171,14 @@ function addBasicAuth(xhr, login, password) {
function onUnexpectedXHRError(xhr) {
window.onUnexpectedXHRError = function () {}

if (Abortarium.isAborted(xhr))
return;

// for manual interception
if ('debuggerHook' in onUnexpectedXHRError) {
onUnexpectedXHRError['debuggerHook'](xhr);
}

var status;
try {status = xhr.status} catch (e) {};

Expand Down
2 changes: 1 addition & 1 deletion deps/menelaus/priv/js/cells.js
Expand Up @@ -41,7 +41,7 @@ future.get = function (ajaxOptions, valueTransformer, nowValue) {
var options = {
valueTransformer: valueTransformer,
cancel: function () {
xhr.abort();
Abortarium.abortRequest(xhr);
},
nowValue: nowValue
}
Expand Down
30 changes: 30 additions & 0 deletions deps/menelaus/priv/js/misc.js
Expand Up @@ -611,3 +611,33 @@ function collectBacktraceViaCaller() {
}
return rv.join('');
}

var Abortarium = {
recentlyAborted: [],
MAX_LENGTH: 50,
abortRequest: function (xhr) {
if (this.isAborted(xhr))
return;
console.log("aborting request:", xhr);
this.recentlyAborted.push(xhr);
if (this.recentlyAborted.length > this.MAX_LENGTH)
this.recentlyAborted = this.recentlyAborted.slice(-this.MAX_LENGTH);
try {
return xhr.abort();
} finally {
try {xhr.onreadystatechange = $.noop();} catch (e) {}
}
},
isAborted: function (xhr) {
return _.include(this.recentlyAborted, xhr);
},
wrapSuccessCallback: function (callback) {
if (!callback)
return callback;
return function (data, status, xhr) {
if (Abortarium.isAborted(xhr))
return;
return callback.apply(this, arguments);
}
}
};

0 comments on commit 752aed8

Please sign in to comment.