@rc-ex/retry
TypeScript icon, indicating that this package has built-in type declarations

1.1.15 • Public • Published

Retry Extension

Retry API calls upon RestException

Install

yarn add @rc-ex/retry

Usage

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
};

Readme

Keywords

none

Package Sidebar

Install

npm i @rc-ex/retry

Weekly Downloads

13

Version

1.1.15

License

MIT

Unpacked Size

8.95 kB

Total Files

7

Last publish

Collaborators

  • tylerlong