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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mimik/request-retry

v3.0.2

Published

Request retry wrapping axios

Downloads

202

Readme

request-retry

Example

const { rpRetry } = require('@mimik/request-retry');

request-retry~rpRetry(options) ⇒ Promise

Make a request with retry.

Kind: inner method of request-retry
Returns: Promise - .
Category: async
Throws:

  • Promise Will throw an error generated by getRichError encapsulating an error generated by request-promise or a TimeoutError.

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

  • retries {int}: maximum number of retries independent to the retryStrategy. The default is 2. If the value is less than 0 the value is set to 0, and if the value is more that 15 the value is set to 15,
  • delay {int}: in millisecond delay between retries if there is no retryDelay strategy. The default is 1000 ms. If the value is less than 20 ms the value is set to 20 ms, and if the value is more than 30000 ms the value is set to 30000 ms,
  • delayStrategy {function}: function describing the delay strategy. The parameters are (nbRetry, err, options, correlationId). Must return a number of miliseconds which is greater to 0 ms but less that 30000 ms, if not the value of delay will be used,
  • logLevel {object}: has the following properties:
    • response: log level to be set for response. The default is silly or if the value is wrong it is set to silly,
    • error: log level to be set for error. The default is silly or if the value is wrong it is set to silly,
    • request: log level to be set for request: The default is silly or if the value is wrong it is set to silly,
    • responseDetails: level of detail when diplaying the response: count, type, full. The default is type or if the value is wrong it is set to type,
    • responseName: name to associate with the response. The default is responseor is the value is not a string or and empty string it is set to response,
  • timeout {int}: in seconds the timeout to be set for the request and retries. If the timeout is reached, a TimeoutError will be generated. The default is 50 seconds. If the value is less than 10 seconds the value is set to 10 seconds, and if the value is more than 120 seconds the value is set to 120 seconds,
  • retryStrategy {function}: function describing the retry strategy. The parameters are (nbRetry, err, options, correlationId). Must return a boolean, if not the function strategy is ignored. The following properties are added to the options object under the 'metrics' property:
  • HTTPRequestDuration function: prom-client function to measure the delay of the request,
  • url: optional url to be added for labelling the metric. If not present the url of the request will be used.

The default retryStategy is:

defaultRetry = (...args) => {
  const { statusCode } = args[1]; // err

  return (statusCode && (Math.floor(statusCode / 100) === 5 || statusCode === 429)) || (!statusCode && !args[1].message.includes('Invalid URI'));
};

If logLevel is empty, request and response will be logged as info and the response will be in response property with full details. Error on the request will generate a warning. If logLevel is not empty but not complete, logLevel will take control over default.

If not alredy set,the user agent will the set to mimik-{serverType}/{serverVersion}/{serverId} {architecture} {node};

To facilitate the transition from request-promise the following action are taken on options:

  • uri takes precednce on url
  • body takes precedence on json if json is an object and are used to assign data
  • qs is used to assign to params

Requires: module:@mimik/sumologic-winston-logger, module:@mimik/response-helper
Fulfil: object - Response of the axios response with option resolveWithFullResponse set to true otherwise only response.data is returned.

| Param | Type | Description | | --- | --- | --- | | options | object | Options for the request. Similar to axios options. validateStatus options is disabled, an error will be created for statusCode outside of [200, 300[. The options resolveWithFullResponse is added and if set to true, the response will be a full axios response. If set to false or missing only reponse.data will be returned. |