Socket
Socket
Sign inDemoInstall

promise-request-retry

Package Overview
Dependencies
69
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    promise-request-retry

Simple wrapper on request-promise for retry mechanism


Version published
Weekly downloads
64K
increased by0.16%
Maintainers
1
Install size
7.66 MB
Created
Weekly downloads
 

Readme

Source

request-promise-retry

npm : promise-request-retry

npm version coverage status build status npm downloads

Simple wrapper on top of request-promise to replicate retry mechanism, i.e, it will try to reprocess the request till a valid response is obtained, or the number of retrys is exhausted. Supports all options from request-promise.

Usage

  • additional parameter retry needed in request-promise options.
  • retry supports boolean (defaults to 1 retry) and positive integer.
  • in order to ignore retry or use genericrequest-promise,just don't specify the retry parameter.
GET Request sample with retry
var rp = require('promise-request-retry');
var options = {
    uri: 'https://api.github.com/user/repos',
    qs: {
        access_token: 'xxxxx xxxxx' // -> uri + '?access_token=xxxxx%20xxxxx'
    },
    headers: {
        'User-Agent': 'Request-Promise'
    },
    json: true, // Automatically parses the JSON string in the response, 
    retry : 2, // will retry the call twice, in case of error.
    verbose_logging : false, // will log errors only, if set to be true, will log all actions
    accepted: [ 400, 404 ] // Accepted HTTP Status codes (will not retry if request response has any of these HTTP Status Code)
    delay: 2000 // will delay retries by 2000 ms.  The default is 100. 
    factor: 2 // will multiple the delay by the factor each time a retry is attempted. 
};

rp(options)
    .then(function (repos) {
        console.log('User has %d repos', repos.length);
    })
    .catch(function (err) {
        // API call failed...
    });
logging sample
2018-03-13T22:20:21.308Z - info: [request-promise-retry] calling http://adadadadad.com/ with retry 3
2018-03-13T22:20:21.899Z - info: [request-promise-retry] Encountered error Error: getaddrinfo ENOTFOUND adadadadad.com adadadadad.com:80 for GET request to http://adadadadad.com/, retry count 3
2018-03-13T22:20:21.904Z - info: [request-promise-retry] Encountered error Error: getaddrinfo ENOTFOUND adadadadad.com adadadadad.com:80 for GET request to http://adadadadad.com/, retry count 2
2018-03-13T22:20:21.907Z - info: [request-promise-retry] Encountered error Error: getaddrinfo ENOTFOUND adadadadad.com adadadadad.com:80 for GET request to http://adadadadad.com/, retry count 1

For rest of samples, please refer request-promise documentation.

Installation

npm install promise-request-retry

Test

npm test

Keywords

FAQs

Last updated on 31 Oct 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc