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

fetch-retry

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-retry

Extend any fetch library with retry functionality

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.4M
decreased by-17.17%
Maintainers
1
Weekly downloads
 
Created

What is fetch-retry?

The fetch-retry npm package is an extension of the native fetch API that adds the ability to automatically retry a failed HTTP request. This is particularly useful for dealing with transient network issues or temporary server-side errors. It allows developers to specify the number of retries, the retry delay, and other retry policies.

What are fetch-retry's main functionalities?

Automatic retries for failed requests

This feature allows fetch requests to be automatically retried a specified number of times with a delay between each attempt. The code sample shows how to wrap the native fetch with fetch-retry to make a GET request that retries up to 3 times with a 1-second delay between retries.

fetch = require('fetch-retry')(require('node-fetch'));

fetch('https://api.example.com', {
  retries: 3,
  retryDelay: 1000
}).then(function(response) {
  return response.json();
}).then(function(json) {
  console.log(json);
}).catch(function(error) {
  console.error(error);
});

Customizable retry on function

This feature allows developers to define a custom function to determine whether a request should be retried based on the attempt number, error, and response. The code sample demonstrates a custom retryOn function that retries the request if an error occurs or if the response status code is 500 or greater.

fetch = require('fetch-retry')(require('node-fetch'));

fetch('https://api.example.com', {
  retries: 4,
  retryDelay: 1000,
  retryOn: function(attempt, error, response) {
    if (error !== null || response.status >= 500) {
      return true;
    }
    return false;
  }
}).then(function(response) {
  return response.json();
}).then(function(json) {
  console.log(json);
}).catch(function(error) {
  console.error(error);
});

Other packages similar to fetch-retry

Keywords

FAQs

Package last updated on 17 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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