npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mimik/request-retry

v4.0.6

Published

Request retry wrapping axios

Downloads

213

Readme

request-retry

Example

import { rpRetry } from '@mimik/request-retry';
or
import rp from '@mimik/request-retry';

request-retry~rpRetry(options) ⇒ Promise

Make a request with retries.

Kind: inner method of request-retry
Category: async
Throws:

  • Error An error produced by getRichError, wrapping an error from request-promise or a TimeoutError.

The following properties may be added to the options object under the retry property:

  • retries {int}: Maximum number of retries, independent of the retryStrategy. Default: 2. If the value is < 0 it is set to 0; if > 15 it is set to 15.
  • delay {int}: Delay between retries in milliseconds when no delayStrategy is provided. Default: 1000. If the value is < 20 it is set to 20; if > 30000 it is set to 30000.
  • delayStrategy {function}: A function that returns the delay (in milliseconds) to wait before the next retry. Signature: (nbRetry, err, options, correlationId). Must return a number > 0 and < 30000; otherwise delay is used.
  • logLevel {object}: Controls logging behavior:
    • response: Log level for responses. Default: silly (invalid values fall back to silly).
    • error: Log level for errors. Default: silly (invalid values fall back to silly).
    • request: Log level for requests. Default: silly (invalid values fall back to silly).
    • responseDetails: Detail level when displaying the response: count, type, or full. Default: type (invalid values fall back to type).
    • responseName: Label associated with the response. Default: response (non-string or empty values fall back to response).
  • timeout {int}: Request timeout (in seconds) applied to the initial request and all retries. If reached, a TimeoutError is thrown. Default: 50. Values < 10 are set to 10; values > 120 are set to 120.
  • retryStrategy {function}: A function that decides whether to retry. Signature: (nbRetry, err, options, correlationId). Must return a boolean; otherwise it is ignored.

The following properties may be added to the options object under the metrics property:

  • HTTPRequestDuration {function}: A prom-client metric function to measure request duration.
  • url {string}: Optional URL label for the metric. If omitted, the request URL is used.

The default retryStrategy is:

defaultRetry = (...args) => {
  const { statusCode } = args[1]; // err
  // Retry on 5xx and 429. If there is no statusCode, retry unless it's an "Invalid URI" error.
  return (statusCode && (Math.floor(statusCode / 100) === 5 || statusCode === 429))
         || (!statusCode && !args[1].message.includes('Invalid URI'));
};

If logLevel is empty, requests and responses are logged at info, the response is logged with full details under the response property, and request errors generate a warn. If logLevel is provided but incomplete, the provided keys override the defaults.

If not already set, the User-Agent header is set to: mimik-{serverType}/{serverVersion}/{serverId} {architecture} {node}.

To ease migration from request-promise, the following adjustments are applied to options:

  • uri takes precedence over url.
  • If json is an object, body takes precedence over json; both are mapped to Axios data.
  • qs is mapped to Axios params.

Requires: module:@mimik/sumologic-winston-logger, module:@mimik/response-helper
Fulfil: object - The Axios response when resolveWithFullResponse is true; otherwise response.data.

| Param | Type | Description | | --- | --- | --- | | options | object | Options for the request (similar to axios). The validateStatus option is disabled: an error is thrown for status codes outside [200, 300). An additional option, resolveWithFullResponse, controls the return shape: when true, the full Axios response object is returned; when false or omitted, only response.data is returned. |