@rc-ex/retry
v1.3.15
Published
Retry extension for ringcentral-extensible project
Downloads
360
Readme
Retry Extension
Retry API calls upon RestException
Install
yarn add @rc-ex/retryUsage
import RingCentral from '@rc-ex/core';
import RetryExtension from '@rc-ex/retry';
const rc = new RingCentral(...);
const retryExtension = new RetryExtension(retryOptions);
await rc.installExtension(retryExtension);Options
RetryOptions
RetryExtension constructor accepts optional RetryOptions as parameter:
type RetryOptions = {
shouldRetry?: ShouldRetry;
retryInterval?: RetryInterval;
};ShouldRetry
ShouldRetry defines condition about should retry or abort:
type ShouldRetry = (
restException: RestException,
retriesAttempted: number,
) => boolean;By default, ShouldRetry returns true when restException.response.status is
429 or 503 and retriesAttempted is smaller than 3:
((restException, retriesAttempted) => {
return retriesAttempted < 3 &&
[429, 503].includes(restException.response.status);
});RetryInterval
RetryInterval defines how long should wait before try:
type RetryInterval = (
restException: RestException,
retriesAttempted: number,
) => number;By default RetryInterval is 60 seconds with exponential back off:
((restException, retriesAttempted) => {
return 60 * 1000 * Math.pow(2, retriesAttempted); // exponential back off
});