Skip to content

Commit 3fab3f9

Browse files
author
Dan Klco
committed
Fixes #86 - Adding support for plugging the fetch implementation and verifying with @adobe/fetch
1 parent 126d3c4 commit 3fab3f9

File tree

4 files changed

+2689
-11951
lines changed

4 files changed

+2689
-11951
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ function shouldRetryOnHttpError(error) {
187187
/**
188188
* @typedef {Object} Options options for fetch-retry
189189
* @property {Object} RetryOptions options for retry or false if want to disable retry
190+
* @property {Function} fetch the fetch implementation to use
190191
* ... other options for fetch call (method, headers, etc...)
191192
*/
192193
/**
@@ -209,13 +210,15 @@ module.exports = async function (url, options) {
209210

210211
let timeoutHandler;
211212
if (retryOptions.socketTimeout) {
212-
const controller = new AbortController();
213+
const abortCon = options.AbortController || AbortController;
214+
const controller = new abortCon();
213215
timeoutHandler = setTimeout(() => controller.abort(), retryOptions.socketTimeout);
214216
options.signal = controller.signal;
215217
}
216218

217219
try {
218-
const response = await fetch(url, options);
220+
const fetchFn = options.fetch || fetch;
221+
const response = await fetchFn(url, options);
219222

220223
if (await shouldRetry(retryOptions, null, response, waitTime)) {
221224
console.error(`Retrying in ${waitTime} milliseconds, attempt ${attempt} failed (status ${response.status}): ${response.statusText}`);

0 commit comments

Comments
 (0)