Skip to main content

RetryErrorHandling

Upgather SDK


Upgather SDK / RetryErrorHandling

Class: RetryErrorHandling

Provides an error handling strategy that supports retries with exponential backoff.

Remarks​

This class implements the ErrorHandlingStrategy interface and allows for retrying failed API calls with configurable backoff, jitter, and retry conditions.

Implements​

Constructors​

new RetryErrorHandling()​

new RetryErrorHandling(maxRetries, options): RetryErrorHandling

Creates an instance of RetryErrorHandling.

Parameters​

maxRetries​

number

The maximum number of retry attempts.

options​

RetryErrorHandlingOptions = {}

Configuration options for retry behavior.

Returns​

RetryErrorHandling

Methods​

getRetryDelay()​

getRetryDelay(attempt): number

Calculates the delay for a given attempt with exponential backoff and jitter.

Parameters​

attempt​

number

The current attempt number.

Returns​

number

The delay in milliseconds.


handleError()​

handleError(response, attempt, originalError): ErrorHandlingResult

Handles the API error by implementing a retry mechanism.

Parameters​

response​

ApiResponse

The API response containing error details.

attempt​

number

The current attempt number.

originalError​

Error

The original error that occurred.

Returns​

ErrorHandlingResult

An ErrorHandlingResult indicating whether to retry or abort.

Implementation of​

ErrorHandlingStrategy.handleError


isRetryableStatusCode()​

isRetryableStatusCode(statusCode): boolean

Determines if a status code represents a retryable error.

Parameters​

statusCode​

number

The HTTP status code to check.

Returns​

boolean

True if the status code represents a retryable error, false otherwise.


shouldRetry()​

shouldRetry(statusCode, attempt, response): boolean

Determines whether a request should be retried.

Parameters​

statusCode​

number

The HTTP status code.

attempt​

number

The current attempt number.

response​

ApiResponse

The full API response.

Returns​

boolean

True if the request should be retried, false otherwise.