Skip to content

Commit

Permalink
Respond only to specific error codes.
Browse files Browse the repository at this point in the history
Only respond to errors that are retryable:
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
  • Loading branch information
execjosh committed Jul 11, 2010
1 parent da3ac0f commit ff1c4fa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/jquery.ajaxretry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit ff1c4fa

Please sign in to comment.