Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
'use strict';

const AbortController = require('abort-controller');
const fetch = require('node-fetch');
const {FetchError} = fetch;

function getTimeRemaining(retryOptions) {
if (retryOptions && retryOptions.startTime && retryOptions.retryMaxDuration) {
Expand Down Expand Up @@ -203,6 +201,7 @@ module.exports = async function (url, options) {

return new Promise(function (resolve, reject) {
const wrappedFetch = async () => {
const FetchError = await import('node-fetch').then( ({ FetchError }) => FetchError);
while (!isResponseTimedOut(retryOptions)) {
++attempt;
const waitTime = getRetryDelay(retryOptions);
Expand All @@ -215,7 +214,7 @@ module.exports = async function (url, options) {
}

try {
const response = await fetch(url, options);
const response = await import('node-fetch').then( ({ default: fetch }) => fetch(url, options));

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