From 01d54e8e49a385a460565ab4f0ebb5584b3042e0 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Sat, 16 Jan 2016 13:39:18 +0500 Subject: [PATCH] filter some nasty errors Related to #119 and #156 --- index.js | 5 +++-- package.json | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6cf8c3b..a66003f 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ const unzipResponse = require('unzip-response'); const createErrorClass = require('create-error-class'); const nodeStatusCodes = require('node-status-codes'); const isPlainObj = require('is-plain-obj'); +const isRetryAllowed = require('is-retry-allowed'); function requestAsEventEmitter(opts) { opts = opts || {}; @@ -254,8 +255,8 @@ function normalizeArguments(url, opts) { if (typeof opts.retries !== 'function') { const retries = opts.retries; - opts.retries = function backoff(iter) { - if (iter > retries) { + opts.retries = function backoff(iter, err) { + if (iter > retries || !isRetryAllowed(err)) { return 0; } diff --git a/package.json b/package.json index 9bad618..dc5de34 100644 --- a/package.json +++ b/package.json @@ -45,11 +45,12 @@ "fetch" ], "dependencies": { - "duplexer3": "^0.1.4", "create-error-class": "^3.0.0", + "duplexer3": "^0.1.4", "get-stream": "^1.1.0", "is-plain-obj": "^1.0.0", "is-redirect": "^1.0.0", + "is-retry-allowed": "^1.0.0", "is-stream": "^1.0.0", "lowercase-keys": "^1.0.0", "node-status-codes": "^2.0.0",