UNPKG

@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.

90 lines 3.2 kB
/** * @module Resilience */ import {} from "../../time-span/implementations/_module.js"; /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Errors */ export class TimeoutResilienceError extends Error { waitTime; static create(waitTime) { return new TimeoutResilienceError(waitTime, `Timeout exceeded: reached limit of ${String(waitTime.toMilliseconds())}ms`); } /** * Note: Do not instantiate `TimeoutResilienceError` 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(waitTime, message, cause) { super(message, { cause }); this.waitTime = waitTime; this.name = TimeoutResilienceError.name; } } /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Errors */ export class RetryResilienceError extends AggregateError { maxAttempts; static create(allErrors, maxAttempts) { return new RetryResilienceError(allErrors, maxAttempts, `Retry limit reached: Failed after ${String(maxAttempts)} attempts`); } /** * Note: Do not instantiate `RetryResilienceError` 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(errors, maxAttempts, message) { super(errors, message); this.maxAttempts = maxAttempts; this.name = RetryResilienceError.name; } } /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Errors */ export class RetryIntervalResilienceError extends AggregateError { attempts; time; interval; static create(allErrors, attempt, time, interval) { return new RetryIntervalResilienceError(allErrors, attempt, time, interval, `Retry limit reached: Failed after ${String(time.toMilliseconds())}ms (Interval: ${String(interval.toMilliseconds())}ms)`); } /** * Note: Do not instantiate `RetryIntervalResilienceError` 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(errors, attempts, time, interval, message) { super(errors, message); this.attempts = attempts; this.time = time; this.interval = interval; this.name = RetryIntervalResilienceError.name; } } /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Errors */ export const RESILIENCE_ERRORS = { RetryInterval: RetryIntervalResilienceError, Retry: RetryResilienceError, Timeout: TimeoutResilienceError, }; /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Errors */ export function isResilienceError(value) { for (const errorClass of Object.values(RESILIENCE_ERRORS)) { if (value instanceof errorClass) { return true; } } return false; } //# sourceMappingURL=resilience.errors.js.map