Installations
npm install @pdedg/promise-retry
Releases
Unable to fetch releases
Developer
odedglas
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
8.9.4
NPM Version
5.4.2
Statistics
1 Stars
9 Commits
5 Branches
1 Contributors
Updated on 14 Aug 2019
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
18,486
Last day
0%
3
Compared to previous day
Last week
75%
7
Compared to previous week
Last month
20%
36
Compared to previous month
Last year
-81.7%
479
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
promise-retry A promise retry executor with exponential backoff strategy. Comes with fetch retry out of the box
Table of Contents
Installation
Install the package:
1npm i @pdedg/promise-retry
API
promiseRetry(fn, [options])
A promise retry executor
- @param {Function} run Function that returns a promise
- @param {Object} Options Execution options
- @param {Function} validateResolved Sample promise resolved result and determines if OK
- @param {Function} retryOn Determines when to retry on error
- @param {Number} retries Amount of retries to execute
- @param {Number|Function} delay The delay between execution ( Can be a function for delay strategies)
- @param {Function} onFailedAttempt Error callback, will be called on each retriable error.
- @param {Function} onBreach - Error callback, will be called on 2 cases: 1) When attempts are equal to retries. 2) On Non retriable error
Examples
1// Simple execution 2 3import { promiseRetry } from '@pdedg/promise-retry'; 4 5const run = () => new Promise((resolve, reject) => reject()); 6promiseRetry(run); // will execute rejected promise by default 3 times and after will trow error
1// With custom delay strategy 2 3import { promiseRetry } from '@pdedg/promise-retry'; 4 5const options = { 6 retries: 5, 7 retryOn: (err) => true, 8 delay: (err) => err.attempt * 1000, 9 onFailedAttempt: (err) => console.log(err.status) 10} 11 12const run = () => new Promise((resolve, reject) => reject()); 13promiseRetry(run); 14/* 15 Will result of: 5 executions of failed promise ( retryOn is set to all ways true ). 16 On each attempt it will execute the onFailedAttempt, and will use linear delay between executions ( last will be 5s delay ) 17 */
fetchRetry(fetch, url, [options])
Wraps a fetch request with retry, by default it will retry on the following http status [408, 503, 504] and on request-timeout error.
- @param {Function} fetch - Can be any fetch implementation ( node-fetch / browser fetch )
- @param {String} url - Request url
- @param {Object} options - fetch retry options
- @param {Number} retries Amount of retries, default to 3
- @param {Number / Function} delay The delay between executions, can be a number for the default backoff strategy OR a custom function
- @param {Function} retryOnResolved When should retry on resolved fetch result
- @param {Function} retryOnError When should retry on error occurred
- @param {Function} onFailedAttempt Error callback, will be called on each retriable error.
- @param {Function} onBreach Error callback, will be called on 2 cases: 1) When attempts are equal to retries. 2) On Non retriable error.
- @param {Object} fetchOptions Normal fetch options you would pass
Examples
1// Simple execution 2 3import { fetchRetry } from '@pdedg/promise-retry'; 4 5const fetch = () => new Promise((resolve, reject) => reject()); 6fetchRetry(fetch, '/end-point', { delay: 100 }); // Will execute 3 fetch calls with 100 / 200 / 400 delay and eventually an error will be thrown.
1// With custom options 2 3import { fetchRetry } from '@pdedg/promise-retry'; 4 5const options = { 6 retries: 2, 7 retryOnResolved: (res) => { 8 if (res.status === 300) { 9 throw new Error('Cannot handle 300 status.') 10 } 11 }, 12} 13 14const fetch = () => new Promise((resolve, reject) => resolve({ status: 300 })); 15fetchRetry(fetch, '/end-point', options) 16/* 17 Will result of: 2 executions of resolved promises, that will be rejected by the validate resolved method. 18 eventually, it will throw an error. 19 */
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/9 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
65 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp
- Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More