Skip to main content

RetryErrorHandlingOptions

Upgather SDK


Upgather SDK / RetryErrorHandlingOptions

Interface: RetryErrorHandlingOptions

Defined in: lib/error/RetryErrorHandling.ts:12

Configuration options for RetryErrorHandling.

Properties

backoffFactor?

optional backoffFactor: number

Defined in: lib/error/RetryErrorHandling.ts:23

Exponential backoff factor.

Default Value

2

errorFormatter()?

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

Defined in: lib/error/RetryErrorHandling.ts:124

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

Defined in: lib/error/RetryErrorHandling.ts:17

Initial delay between retries in milliseconds.

Default Value

300

jitterFactor?

optional jitterFactor: number

Defined in: lib/error/RetryErrorHandling.ts:29

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

Default Value

0.1

logger?

optional logger: LoggerInterface

Defined in: lib/error/RetryErrorHandling.ts:75

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/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

Defined in: lib/error/RetryErrorHandling.ts:47

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

Defined in: lib/error/RetryErrorHandling.ts:35

Maximum delay between retries in milliseconds.

Default Value

30000

retryableStatusCodes?

optional retryableStatusCodes: number[]

Defined in: lib/error/RetryErrorHandling.ts:92

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

Defined in: lib/error/RetryErrorHandling.ts:106

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.