@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
61 lines • 2.21 kB
JavaScript
/**
* @module CircuitBreaker
*/
import {} from "../../namespace/_module.js";
/**
* The error is thrown when circuit breaker is in open state and will not allow any attempts.
*
* IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/contracts"`
* @group Errors
*/
export class OpenCircuitBreakerError extends Error {
static create(key, cause) {
return new OpenCircuitBreakerError(`Circuit breaker for key "${key.get()}" in opened state. All calls are being blocked until transitioned to half opened state.`, cause);
}
/**
* Note: Do not instantiate `OpenCircuitBreakerError` directly via the constructor. Use the static `create()` factory method instead.
* The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors.
* @internal
*/
constructor(message, cause) {
super(message, { cause });
this.name = OpenCircuitBreakerError.name;
}
}
export class IsolatedCircuitBreakerError extends Error {
static create(key, cause) {
return new IsolatedCircuitBreakerError(`Circuit breaker for key "${key.get()}" is manually isolated. All calls are being blocked until reseted.`, cause);
}
/**
* Note: Do not instantiate `IsolatedCircuitBreakerError` directly via the constructor. Use the static `create()` factory method instead.
* The constructor remains public only to maintain compatibility with errorPolicy types and prevent type errors.
* @internal
*/
constructor(message, cause) {
super(message, { cause });
this.name = IsolatedCircuitBreakerError.name;
}
}
/**
*
* IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/contracts"`
* @group Errors
*/
export const CIRCUIT_BREAKER_ERRORS = {
Open: OpenCircuitBreakerError,
Isolated: IsolatedCircuitBreakerError,
};
/**
*
* IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/contracts"`
* @group Errors
*/
export function isCircuitBreakerError(value) {
for (const ErrorClass of Object.values(CIRCUIT_BREAKER_ERRORS)) {
if (!(value instanceof ErrorClass)) {
return false;
}
}
return true;
}
//# sourceMappingURL=circuit-breaker.errors.js.map