Skip to main content

CircuitBreakerErrorHandling

Upgather SDK


Upgather SDK / CircuitBreakerErrorHandling

Class: CircuitBreakerErrorHandling

Circuit breaker implementation that prevents repeated calls to failing services.

Remarks

The circuit breaker pattern prevents cascading failures by stopping requests to failing services. It implements three states:

  • closed: Normal operation, all requests proceed
  • open: Service is failing, requests are prevented
  • half-open: Testing if service has recovered, allows a single request

Implements

Constructors

new CircuitBreakerErrorHandling()

new CircuitBreakerErrorHandling(fallbackStrategy, options): CircuitBreakerErrorHandling

Creates a new circuit breaker error handling strategy.

Parameters

fallbackStrategy

ErrorHandlingStrategy

The error handling strategy to delegate to when circuit is not open

options

CircuitBreakerOptions = {}

Circuit breaker configuration options

Returns

CircuitBreakerErrorHandling

Methods

getCircuitState()

getCircuitState(url): "closed" | "open" | "half-open"

Get the current state of the circuit for a URL.

Parameters

url

string

The URL to check

Returns

"closed" | "open" | "half-open"

The current circuit state


handleError()

handleError(response, attempt, originalError): ErrorHandlingResult

Handles errors by recording failures and delegating to the fallback strategy.

Parameters

response

ApiResponse

The API response containing error details

attempt

number

The current attempt number

originalError

Error

The original error that occurred

Returns

ErrorHandlingResult

Error handling result from the fallback strategy

Implementation of

ErrorHandlingStrategy.handleError


recordSuccess()

recordSuccess(url): void

Record a successful request to potentially close an open circuit.

Parameters

url

string

The URL that was successfully requested

Returns

void


shouldAllowRequest()

shouldAllowRequest(url): boolean

Check if a request should be allowed to proceed. This should be called before making a request.

Parameters

url

string

The URL to check

Returns

boolean

True if request should proceed, false if circuit is open