Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using esm modules via dynamic imports #101

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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