Giter Club home page Giter Club logo

fetch-retry's Introduction

fetch-retry CircleCI

A layer on top of fetch (via node-fetch) with sensible defaults for retrying to prevent common errors.

How to use

fetch-retry is a drop-in replacement for fetch:

const fetch = require('@zeit/fetch-retry')(require('node-fetch'))

module.exports = async () => {
  const res = await fetch('http://localhost:3000')
  console.log(res.status);
}

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

Note that you can pass retry options to using opts.retry. We also provide a opts.onRetry which is a customized version of opts.retry.onRetry and passes not only the error object in each retry but also the current opts object.

Rationale

Some errors are very common in production (like the underlying Socket yielding ECONNRESET), and can easily and instantly be remediated by retrying.

The default behavior of fetch-retry is to attempt retries 10, 50 and 250 milliseconds (a total of 3 retires) after a network error or 5xx error occur.

The idea is to provide a sensible default: most applications should continue to perform correctly with a worst case scenario of a given request having an additional 250ms overhead.

On the other hand, most applications that use fetch-retry instead of vanilla fetch should see lower rates of common errors and fewer 'glitches' in production.

Tests

To run rests, execute

npm test

fetch-retry's People

Contributors

igorklopov avatar javivelasco avatar rauchg avatar styfle avatar tootallnate avatar zkochan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.