Socket
Book a DemoInstallSign in
Socket

@dataforsyningen/retry

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dataforsyningen/retry

Klimadatastyrelsen's fetch retry library.

0.1.3
latest
Source
npmnpm
Version published
Maintainers
2
Created
Source

Retry

A npm package for easily adding retry to fetch calls.

Getting Started

Install the npm package:

npm install @dataforsyningen/retry

Import the options and functions you need, for instance:

import { retryOptions, fetchWithRetry } from '@dataforsyningen/retry/index.js'

You can set global options like this:

// Set the default retry timeout.
retryOptions.timeout = 200
// disable dynamically updating timeout.
retryOptions.dynamicTimeout = false

And you can use the retry with fetch like the usual fetch calls:

fetchWithRetry(resource, options)

You can pass custom parameters in the options object in additional to fetch's usual options (see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit).

Here are the possible options:

NameDefaultDescription
retries4The number of times the application should attempt to retry API calls.
timeout500The time the application should wait before attempting a retry.
growthFactor2The exponential growth factor which the timeout is multiplied by after each failed attempt.
statusCodes[408, 500, 502, 503, 504, 506, 507, 508, 510]The response status codes where a retry should be attempted.

Here is an example of how to use it with an OpenLayers WMTS source:

import WMTS from 'ol/source/WMTS'
import TileState from 'ol/TileState.js'

// create an options object to use in a WMTS source constructor. 
const options = {
    ...
}

// Add retry to the tileLoadFunction.
options.tileLoadFunction = function (tile, src) {
fetchWithRetry(src)
    .then(response => {
        if (!response.ok) {
            tile.setState(TileState.ERROR)
        }
        return response.blob()
    })
    .then(blob => {
        tile.getImage().src = URL.createObjectURL(blob)
    })
    .catch((e) => {
        tile.setState(TileState.ERROR)
    })
}

// Create the WMTS Source.
const wmtsSource = new WMTS(options)

Keywords

Klimadatastyrelsen

FAQs

Package last updated on 30 Jun 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.