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

@zeit/fetch-retry

Package Overview
Dependencies
Maintainers
45
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 3.0.0 to 4.0.0

.circleci/config.yml

5

index.js

@@ -35,2 +35,3 @@ const retry = require('async-retry');

const {method = 'GET'} = opts;
const isRetry = attempt < retryOpts.retries;
try {

@@ -40,3 +41,3 @@ // this will be retried

debug('status %d', res.status);
if (res.status >= 500 && res.status < 600) {
if (res.status >= 500 && res.status < 600 && isRetry) {
const err = new Error(res.statusText);

@@ -50,3 +51,3 @@ err.code = err.status = err.statusCode = res.status;

} catch (err) {
debug(`${method} ${url} error (${err.status}). ${attempt < MAX_RETRIES ? 'retrying' : ''}`, err);
debug(`${method} ${url} error (${err.status}). ${isRetry ? 'retrying' : ''}`, err);
throw err;

@@ -53,0 +54,0 @@ }

2

package.json
{
"name": "@zeit/fetch-retry",
"version": "3.0.0",
"version": "4.0.0",
"devDependencies": {

@@ -5,0 +5,0 @@ "jest": "^21.2.1",

@@ -1,2 +0,2 @@

# fetch-retry
# fetch-retry [![CircleCI](https://circleci.com/gh/zeit/fetch-retry.svg?style=svg)](https://circleci.com/gh/zeit/fetch-retry)

@@ -3,0 +3,0 @@ A layer on top of `fetch` (via [node-fetch](https://www.npmjs.com/package/node-fetch))

@@ -31,3 +31,3 @@ const {createServer} = require('http');

test('fails on >MAX_RETRIES', async () => {
test('resolves on >MAX_RETRIES', async () => {
const server = createServer((req, res) => {

@@ -41,10 +41,6 @@ res.writeHead(500);

const {port} = server.address();
try {
await retryFetch(`http://127.0.0.1:${port}`);
} catch (err) {
expect(await err.status).toBe(500);
server.close();
return resolve();
}
reject(new Error('must fail'));
const res = await retryFetch(`http://127.0.0.1:${port}`);
expect(res.status).toBe(500);
server.close();
return resolve();
});

@@ -68,13 +64,9 @@ server.on('error', reject);

const {port} = server.address();
try {
await retryFetch(`http://127.0.0.1:${port}`, opts);
} catch (err) {
expect(opts.onRetry.mock.calls.length).toBe(3);
expect(opts.onRetry.mock.calls[0][0]).toEqual(err);
expect(opts.onRetry.mock.calls[0][1]).toEqual(opts);
expect(await err.status).toBe(500);
server.close();
return resolve();
}
reject(new Error('must fail'));
const res = await retryFetch(`http://127.0.0.1:${port}`, opts);
expect(opts.onRetry.mock.calls.length).toBe(2);
expect(opts.onRetry.mock.calls[0][0]).toBeInstanceOf(Error);
expect(opts.onRetry.mock.calls[0][1]).toEqual(opts);
expect(res.status).toBe(500);
server.close();
return resolve();
});

@@ -81,0 +73,0 @@ server.on('error', reject);

Sorry, the diff of this file is not supported yet

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