@clappr/retry-utils
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -1,2 +0,2 @@ | ||
var r={d:(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:(r,e)=>Object.prototype.hasOwnProperty.call(r,e)},e={};r.d(e,{U:()=>o});const t=function(r){return!r||Number.isNaN(r)?1:Math.random()+r};var n=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return r.includes(e)};const o=function(r){var e=r.action,o=r.maxAttempts,i=void 0===o?3:o,a=r.baseDelay,c=void 0===a?100:a,u=r.backOffFactor,s=void 0===u?2:u,f=r.retryableErrors,y=void 0===f?null:f,d=0,l=[];return function r(){return e&&"function"==typeof e?e().then((function(r){return{retryResponse:r,retryHistory:l}})).catch((function(e){if(y&&!n(y,e.statusCode))return Promise.reject({retryError:e,retryHistory:l});var o,a,u;if(l.push((o={},a="attempt_".concat(d),u=e,a in o?Object.defineProperty(o,a,{value:u,enumerable:!0,configurable:!0,writable:!0}):o[a]=u,o)),d===i)return Promise.reject({retryError:e,retryHistory:l});d++;var f=Math.pow(s,d-1)*c,m=f*t(.5);return console.log("Retrying...\nIf the retries fail we delay the next attempt in ".concat(f/1e3," seconds\n Fuzz factor for retry: ").concat(m)),new Promise((function(e){setTimeout((function(){e(r())}),m)}))})):Promise.reject({retryError:"Action must be defined and a function",retryHistory:l})}()};var i=e.U;export{i as retryPromise}; | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmV0cnktdXRpbHMuanMiLCJtYXBwaW5ncyI6IkFBQ0EsSUFBSUEsRUFBc0IsQ0NBMUIsRUFBd0IsQ0FBQ0MsRUFBU0MsS0FDakMsSUFBSSxJQUFJQyxLQUFPRCxFQUNYRixFQUFvQkksRUFBRUYsRUFBWUMsS0FBU0gsRUFBb0JJLEVBQUVILEVBQVNFLElBQzVFRSxPQUFPQyxlQUFlTCxFQ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ic3RhdHVzQ29kZSIsIlByb21pc2UiLCJyZWplY3QiLCJwdXNoIiwiYmFzZURlbGF5QmFja09mZiIsInBvdyIsImZ1enplZERlbGF5IiwicmFuZG9tSW50ZXJ2YWxQZXJjZW50YWdlIiwiY29uc29sZSIsImxvZyIsInJlc29sdmUiLCJzZXRUaW1lb3V0Il0sInNvdXJjZVJvb3QiOiIifQ== | ||
var r={d:function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:function(r,e){return Object.prototype.hasOwnProperty.call(r,e)}},e={};r.d(e,{U:function(){return o}});var t=function(r){return!r||Number.isNaN(r)?1:Math.random()+r};var n=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1;return r.includes(e)},o=function(r){var e=r.action,o=r.maxAttempts,i=void 0===o?3:o,a=r.baseDelay,c=void 0===a?100:a,u=r.backOffFactor,f=void 0===u?2:u,s=r.retryableErrors,y=void 0===s?null:s,d=0,l=[];return function r(){return e&&"function"==typeof e?e().then((function(r){return{retryResponse:r,retryHistory:l}})).catch((function(e){if(y&&!n(y,e.statusCode))return Promise.reject({retryError:e,retryHistory:l});var o,a,u;if(l.push((o={},a="attempt_".concat(d),u=e,a in o?Object.defineProperty(o,a,{value:u,enumerable:!0,configurable:!0,writable:!0}):o[a]=u,o)),d===i)return Promise.reject({retryError:e,retryHistory:l});d++;var s=Math.pow(f,d-1)*c,m=s*t(.5);return console.log("Retrying...\nIf the retries fail we delay the next attempt in ".concat(s/1e3," seconds\n Fuzz factor for retry: ").concat(m)),new Promise((function(e){setTimeout((function(){e(r())}),m)}))})):Promise.reject({retryError:"Action must be defined and a function",retryHistory:l})}()},i=e.U;export{i as retryPromise}; | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmV0cnktdXRpbHMuanMiLCJtYXBwaW5ncyI6IkFBQ0EsSUFBSUEsRUFBc0IsQ0NBMUIsRU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iYWNrT2ZmRmFjdG9yIiwibnVtYmVyT2ZBdHRlbXB0cyIsInJldHJ5SGlzdG9yeSIsInJldHJ5QXR0ZW1wdCIsInRoZW4iLCJyZXRyeVJlc3BvbnNlIiwiY2F0Y2giLCJyZXRyeUVycm9yIiwic3RhdHVzQ29kZSIsIlByb21pc2UiLCJyZWplY3QiLCJwdXNoIiwiYmFzZURlbGF5QmFja09mZiIsInBvdyIsImZ1enplZERlbGF5IiwicmFuZG9tSW50ZXJ2YWxQZXJjZW50YWdlIiwiY29uc29sZSIsImxvZyIsInJlc29sdmUiLCJzZXRUaW1lb3V0Il0sInNvdXJjZVJvb3QiOiIifQ== |
@@ -50,3 +50,3 @@ import randomIntervalPercentage from './utils/randomIntervalPercentage' | ||
const isErrorRetryable = (retryableErrors, currentError = '') => { | ||
const isErrorRetryable = (retryableErrors, currentError = -1) => { | ||
return retryableErrors.includes(currentError) | ||
@@ -53,0 +53,0 @@ } |
{ | ||
"name": "@clappr/retry-utils", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "reusable retry logic using exponential backoff pattern", | ||
"main": "./dist/retry-utils.js", | ||
"scripts": { | ||
"test": "jest --no-console", | ||
"test": "jest --coverage --silent", | ||
"build": "webpack", | ||
@@ -50,3 +50,14 @@ "build:dev": "webpack", | ||
"test": "tests" | ||
} | ||
}, | ||
"engines": { | ||
"node": "^12" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"browserslist": [ | ||
"> 0.5%", | ||
"last 2 versions", | ||
"not ie <= 11" | ||
] | ||
} |
# Retry Utils | ||
[![npm version](https://badge.fury.io/js/@clappr%2Fretry-utils.svg)](https://badge.fury.io/js/@clappr%2Fretry-utils) | ||
[![npm bundle size](https://img.shields.io/bundlephobia/min/@clappr/retry-utils?style=flat-square)](https://bundlephobia.com/result?p=@clappr/retry-utils) | ||
[![Build Status](https://app.travis-ci.com/clappr/retry-utils.svg?branch=main)](https://app.travis-ci.com/clappr/retry-utils) | ||
![Travis (.com)](https://img.shields.io/travis/com/clappr/retry-utils?style=flat-square) | ||
This lib aims to apply retry patterns for various needed situations. The definitions were inspired by the [retry implementation of Shaka Player](https://github.com/google/shaka-player/blob/df5340fa2b708245f1737f6928f4452425d5341a/docs/tutorials/network-and-buffering-config.md). | ||
@@ -24,3 +29,3 @@ | ||
backOffFactor: 'The multiplier for successive retry delays' | ||
retryableErrors: 'A array specifying which HTTP status should be at retry flow' | ||
retryableErrors: 'A array specifying which HTTP status should be at retry flow' (**) | ||
} | ||
@@ -31,2 +36,6 @@ ``` | ||
(**) To use the `retryableErrors` property you must pass the status code into the error object, like demonstrated in `Examples` section (`getSomething` method). | ||
<br> | ||
The `retryPromise` method apply a fuzz factor of 50% in either direction. So if the ideal delay is `1000ms`, the actual delay will be randomly chosen between `500ms` and `1500ms`. | ||
@@ -75,3 +84,3 @@ | ||
if (response.ok) return response | ||
throw new Error(response.statusText) | ||
throw new Error({ statusCode: response.status }) | ||
}) | ||
@@ -89,4 +98,4 @@ } | ||
retryPromise(retryParameters) | ||
.then(() => console.log('Retry success')) | ||
.catch(() => console.log('Retry error')) | ||
.then((data) => console.log('Retry success ', data)) | ||
.catch((error) => console.log('Retry error ', error)) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15403
59
98