new Client(circuitBreakerOptions, requestOptions)
Constructs a ResilientClient.
Parameters:
Name | Type | Description |
---|---|---|
circuitBreakerOptions |
CircuitBreaker.Options | Options for the circuit breaker |
requestOptions |
AxiosRequestConfig | Options for the Fetcher |
Methods
getCircuitBreaker(indexObject) → {CircuitBreaker}
Get an specific circuit breaker.
Helpful when you need to get stats from a circuit breaker.
Parameters:
Name | Type | Description |
---|---|---|
indexObject |
BreakerIndexObject | IndexObject contains the URL and method of the request associated with a circuit breaker. Request and URL together are used as index for the circuit breaker. They can be formatted into an string index using BreakerIndexObject |
Returns:
Circuit breaker
- Type
- CircuitBreaker
request(fetchConfig) → {Promise.<AxiosResponse>}
Perform a HTTP request that might fails
Parameters:
Name | Type | Description |
---|---|---|
fetchConfig |
AxiosRequestConfig | Options for the Fetcher |
Returns:
Promise resolves with the HTTP response
on success or is rejected on failure of the action. Use isBreakerError()
to determine if a rejection was a result of the circuit breaker or the
HTTP call.
- Type
- Promise.<AxiosResponse>
(static) isBreakerError(error) → {Boolean}
Returns true if the provided error was generated by an circuit breaker. It will be false
if the error came from the action itself.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | The Error to check |
Returns:
true if the error was generated by an circuit breaker
- Type
- Boolean