Skip to main content

RetryErrorHandlingOptions

Upgather SDK


Upgather SDK / RetryErrorHandlingOptions

Interface: RetryErrorHandlingOptions

Configuration options for RetryErrorHandling.

Properties​

backoffFactor?​

optional backoffFactor: number

Exponential backoff factor.

Default Value​

2

errorFormatter()?​

optional errorFormatter: (response, originalError, attempts) => Error

Custom error formatter for when retries are exhausted.

Parameters​

response​

ApiResponse

The API response containing error information

originalError​

Error

The original error that was thrown

attempts​

number

The number of retry attempts that were made

Returns​

Error

A formatted error object

Remarks​

Use this to customize how errors are formatted after all retry attempts have failed. The formatter receives the raw API response, original error, and the number of attempts made.


initialDelay?​

optional initialDelay: number

Initial delay between retries in milliseconds.

Default Value​

300

jitterFactor?​

optional jitterFactor: number

Jitter factor to prevent thundering herd problems (0.1 = 10%).

Default Value​

0.1

logger?​

optional logger: LoggerInterface

Logger instance for retry logging. Takes precedence over logRetryAttempts flag.

Remarks​

If provided, this logger will be used for all retry-related logging operations. If not provided and logRetryAttempts is true, retries will be logged to console directly. If not provided and logRetryAttempts is false, no logging will occur.

Example​

Using a custom logger with retry handler:

import { RetryErrorHandling, LoggerInterface } from '@upgather/sdk';

const myLogger: LoggerInterface = {
debug: (msg) => console.debug(msg),
info: (msg) => console.info(msg),
warn: (msg) => console.warn(msg),
error: (msg) => console.error(msg),
};

const retryHandler = new RetryErrorHandling(3, {
initialDelay: 500,
logger: myLogger,
});

logRetryAttempts?​

optional logRetryAttempts: boolean

Whether to log retry attempts to console.

Deprecated​

Use the logger property instead for more control over logging behavior. This property is maintained for backward compatibility.

Default Value​

true

Remarks​

When both logRetryAttempts and logger are provided, the logger property takes precedence.


maxDelay?​

optional maxDelay: number

Maximum delay between retries in milliseconds.

Default Value​

30000

retryableStatusCodes?​

optional retryableStatusCodes: number[]

Custom HTTP status codes that should trigger a retry.

Remarks​

By default, the following status codes are retryable:

  • 0 (network error)
  • 408 (Request Timeout)
  • 429 (Too Many Requests)
  • 500 (Internal Server Error)
  • 502 (Bad Gateway)
  • 503 (Service Unavailable)
  • 504 (Gateway Timeout)

Additional status codes provided here will be added to the default list.


retryDecider()?​

optional retryDecider: (statusCode, attempt, response) => boolean

Custom function to determine if an error should be retried.

Parameters​

statusCode​

number

The HTTP status code of the failed request

attempt​

number

The current attempt number

response​

ApiResponse

The API response containing error details

Returns​

boolean

True if the request should be retried, false otherwise

Remarks​

This function is called before checking the default retryable status codes. If provided, it takes precedence over the default retry logic.