Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zeit/fetch-retry

Package Overview
Dependencies
Maintainers
12
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zeit/fetch-retry - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

.npmignore

75

index.js

@@ -1,13 +0,1 @@

let fetch;
try {
fetch = require('node-fetch');
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND' && /node-fetch/.test(err.message)) {
console.error('Could not find peer dependency `node-fetch`. ' +
'Make sure it is installed: `yarn add node-fetch`');
}
throw err;
}
const retry = require('async-retry');

@@ -21,29 +9,42 @@ const debug = require('debug')('fetch-retry');

const fetchRetry = (url, opts = {}, retryOpts) => (
retry(async (bail, attempt) => {
const {method = 'GET'} = opts;
try {
// this will be retried
const res = await fetch(url, opts);
debug('status %d', res.status);
if (res.status >= 500 && res.status < 600) {
const err = new Error(res.statusText);
err.code = err.status = err.statusCode = res.status;
err.url = url;
module.exports = setup;
function setup(fetch) {
if (!fetch) {
fetch = require('node-fetch');
}
function fetchRetry(url, opts = {}, retryOpts) {
return retry(async (bail, attempt) => {
const {method = 'GET'} = opts;
try {
// this will be retried
const res = await fetch(url, opts);
debug('status %d', res.status);
if (res.status >= 500 && res.status < 600) {
const err = new Error(res.statusText);
err.code = err.status = err.statusCode = res.status;
err.url = url;
throw err;
} else {
return res;
}
} catch (err) {
debug(`${method} ${url} error (${err.status}). ${attempt < MAX_RETRIES ? 'retrying' : ''}`, err);
throw err;
} else {
return res;
}
} catch (err) {
debug(`${method} ${url} error (${err.status}). ${attempt < MAX_RETRIES ? 'retrying' : ''}`, err);
throw err;
}
}, retryOpts || {
// timeouts will be [ 10, 50, 250 ]
minTimeout: MIN_TIMEOUT,
retries: MAX_RETRIES,
factor: FACTOR
})
);
}, retryOpts || {
// timeouts will be [ 10, 50, 250 ]
minTimeout: MIN_TIMEOUT,
retries: MAX_RETRIES,
factor: FACTOR
})
}
module.exports = fetchRetry;
for (const key of Object.keys(fetch)) {
fetchRetry[key] = fetch[key];
}
fetchRetry.default = fetchRetry;
return fetchRetry;
}
{
"name": "@zeit/fetch-retry",
"version": "1.0.1",
"version": "2.0.0",
"devDependencies": {

@@ -8,4 +8,8 @@ "jest": "^21.2.1",

},
"peerDependencies": {
"node-fetch": "*"
},
"dependencies": {
"async-retry": "^1.1.3"
"async-retry": "^1.1.3",
"debug": "^3.1.0"
},

@@ -12,0 +16,0 @@ "scripts": {

@@ -11,3 +11,4 @@ # fetch-retry

```js
const fetch = require('@zeit/fetch-retry');
const fetch = require('@zeit/fetch-retry')(require('node-fetch'))
module.exports = async () => {

@@ -19,3 +20,3 @@ const res = await fetch('http://localhost:3000')

Make sure to `yarn add fetch-retry` in your main package.
Make sure to `yarn add @zeit/fetch-retry` in your main package.

@@ -22,0 +23,0 @@ The third optional parameter is custom [retry options](https://github.com/zeit/async-retry)

const {createServer} = require('http');
const retryFetch = require('./index');
const retryFetch = require('./index')();

@@ -4,0 +4,0 @@ test('retries upon 500', async () => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc