@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.
48 lines • 1.59 kB
JavaScript
/**
* @module RateLimiter
*/
import {} from "../../namespace/contracts/_module.js";
import {} from "../../rate-limiter/contracts/rate-limiter-state.contract.js";
import {} from "../../utilities/_module.js";
/**
* The error is throw when rate limiter blocks the attempts.
*
* IMPORT_PATH: `"@daiso-tech/core/rate-limiter/contracts"`
* @group Errors
*/
export class BlockedRateLimiterError extends Error {
state;
static create(state, key, cause) {
return new BlockedRateLimiterError(state, `Rate limiter for key "${key.get()}" is blocked. All calls are being blocked until wait time is reached.`, cause);
}
/**
* Note: Do not instantiate `BlockedRateLimiterError` 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(state, message, cause) {
super(message, { cause });
this.state = state;
this.name = BlockedRateLimiterError.name;
}
}
/**
* IMPORT_PATH: `"@daiso-tech/core/rate-limiter/contracts"`
* @group Errors
*/
export const RATE_LIMITER_ERRORS = {
Blocked: BlockedRateLimiterError,
};
/**
* IMPORT_PATH: `"@daiso-tech/core/rate-limiter/contracts"`
* @group Errors
*/
export function isRateLimiterError(value) {
for (const errorClass of Object.values(RATE_LIMITER_ERRORS)) {
if (value instanceof errorClass) {
return true;
}
}
return false;
}
//# sourceMappingURL=rate-limiter.errors.js.map