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

Fixes tests for node 18, updates deps, adds native node example #83

Merged
merged 3 commits into from
Feb 26, 2023
Merged
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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# fetch-retry

Adds retry functionality to the `Fetch` API.
Adds retry functionality to the [Fetch](https://fetch.spec.whatwg.org/) API.

It wraps any `Fetch` API package (eg: [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), [cross-fetch](https://github.com/lquixada/cross-fetch), [isomorphic-unfetch](https://github.com/developit/unfetch) and etc.) and retries requests that fail due to network issues. It can also be configured to retry requests on specific HTTP status codes.
It wraps any `fetch` API package (eg: [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), [cross-fetch](https://github.com/lquixada/cross-fetch), [isomorphic-unfetch](https://github.com/developit/unfetch), or [Node.js native's fetch implementation](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch)) and retries requests that fail due to network issues. It can also be configured to retry requests on specific HTTP status codes.

[![Build Status](https://travis-ci.org/jonbern/fetch-retry.svg?branch=master)](https://travis-ci.org/jonbern/fetch-retry)

## npm package

Expand All @@ -18,10 +17,11 @@ npm install fetch-retry --save
These properties are optional, and unless different defaults have been specified when requiring `fetch-retry`, these will default to 3 retries, with a 1000ms retry delay, and to only retry on network errors.

```javascript
require('es6-promise').polyfill();
const originalFetch = require('isomorphic-fetch');
const fetch = require('fetch-retry')(originalFetch);

var originalFetch = require('isomorphic-fetch');
var fetch = require('fetch-retry')(originalFetch);
// fetch-retry can also wrap Node.js's native fetch API implementation:
const fetch = require('fetch-retry')(global.fetch);
```

```javascript
Expand All @@ -41,8 +41,8 @@ fetch(url, {
or passing your own defaults:

```javascript
var originalFetch = require('isomorphic-fetch');
var fetch = require('fetch-retry')(originalFetch, {
const originalFetch = require('isomorphic-fetch');
const fetch = require('fetch-retry')(originalFetch, {
retries: 5,
retryDelay: 800
});
Expand Down
6 changes: 4 additions & 2 deletions dist/fetch-retry.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.fetchRetry = factory());
}(this, (function () { 'use strict';
})(this, (function () { 'use strict';

var fetchRetry = function (fetch, defaults) {
defaults = defaults || {};
Expand Down Expand Up @@ -66,6 +66,8 @@
// eslint-disable-next-line no-undef
return new Promise(function (resolve, reject) {
var wrappedFetch = function (attempt) {
// As of node 18, this is no longer needed since node comes with native support for fetch:
/* istanbul ignore next */
var _input =
typeof Request !== 'undefined' && input instanceof Request
? input.clone()
Expand Down Expand Up @@ -146,4 +148,4 @@

return fetchRetry;

})));
}));
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ module.exports = function (fetch, defaults) {
// eslint-disable-next-line no-undef
return new Promise(function (resolve, reject) {
var wrappedFetch = function (attempt) {
// As of node 18, this is no longer needed since node comes with native support for fetch:
/* istanbul ignore next */
var _input =
typeof Request !== 'undefined' && input instanceof Request
? input.clone()
Expand Down
Loading