Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
really not clone, reuse the originally agent by default, can specify one in retry strategy, even remove it via null value
  • Loading branch information
emmansun committed Nov 4, 2020
1 parent 8c85f72 commit a237f20
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Expand Up @@ -131,11 +131,16 @@ Request.prototype._tryUntilFail = function () {
}

const originalAgent = this.options.agent;
var mustRetry = await Promise.resolve(this.retryStrategy(err, response, body, _.cloneDeep(this.options)));
delete this.options.agent;
const clonedOptions = _.cloneDeep(this.options);
this.options.agent = originalAgent;
var mustRetry = await Promise.resolve(this.retryStrategy(err, response, body, clonedOptions));
if (_.isObject(mustRetry) && _.has(mustRetry, 'mustRetry')) {
if (_.isObject(mustRetry.options)) {
this.options = mustRetry.options; //if retryStrategy supposes different request options for retry
this.options.agent = originalAgent;
if (originalAgent && typeof this.options.agent === 'undefined') {
this.options.agent = originalAgent;
}
}
mustRetry = mustRetry.mustRetry;
}
Expand Down

0 comments on commit a237f20

Please sign in to comment.