Skip to content
Browse files

Respond only to specific error codes.

Only respond to errors that are retryable:
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
  • Loading branch information...
1 parent da3ac0f commit ff1c4fa3a2976f9d9e6891c8ce93e704f3386cfa @execjosh committed Jul 11, 2010
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/jquery.ajaxretry.js
View
5 src/jquery.ajaxretry.js
@@ -23,11 +23,13 @@
DEF_DELAY_FUNC = function(i){
return Math.floor(Math.random() * ((2 << i) - 1));
},
+ DEF_ERROR_CODES = [502,503,504],
DEF_SLOT_TIME = 1000,
DEF_OPTS = {
attempts: DEF_ATTEMPTS,
cutoff: DEF_CUTOFF,
delay_func: DEF_DELAY_FUNC,
+ error_codes: DEF_ERROR_CODES,
slot_time: DEF_SLOT_TIME,
tick: NOP_FUNC
},
@@ -73,8 +75,9 @@
// Override error function
settings.error = function(xhr_obj, textStatus, errorThrown){
+ var can_retry = 0 <= $.inArray(xhr_obj.status, opts.error_codes);
failures++;
- if (failures >= opts.attempts) {
+ if (!can_retry || failures >= opts.attempts) {
// Give up and call the original error function
window.setTimeout(function(){orig_err_func(xhr_obj, textStatus, errorThrown)}, 0);
}

0 comments on commit ff1c4fa

Please sign in to comment.
Something went wrong with that request. Please try again.