@stimulcross/rate-limiter 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { CustomError } from './custom.error.js';
1
2
  import { RateLimitErrorCode } from '../enums/rate-limit-error-code.js';
2
3
  export interface RateLimitErrorPlainObject extends Error {
3
4
  code: RateLimitErrorCode;
@@ -17,7 +18,7 @@ export interface RateLimitErrorPlainObject extends Error {
17
18
  * - `DESTROYED` - When the task is destroyed due to the rate limiter's `clear()` or `destroy()` methods.
18
19
  * - `CANCELLED` - When the task is cancelled using an abort signal.
19
20
  */
20
- export declare class RateLimitError extends Error {
21
+ export declare class RateLimitError extends CustomError {
21
22
  private readonly _code;
22
23
  private readonly _retryAt;
23
24
  /** @internal */
@@ -1,3 +1,4 @@
1
+ import { CustomError } from './custom.error.js';
1
2
  import { RateLimitErrorCode } from '../enums/rate-limit-error-code.js';
2
3
  /**
3
4
  * An error thrown when a rate limit is exceeded.
@@ -13,7 +14,7 @@ import { RateLimitErrorCode } from '../enums/rate-limit-error-code.js';
13
14
  * - `DESTROYED` - When the task is destroyed due to the rate limiter's `clear()` or `destroy()` methods.
14
15
  * - `CANCELLED` - When the task is cancelled using an abort signal.
15
16
  */
16
- export class RateLimitError extends Error {
17
+ export class RateLimitError extends CustomError {
17
18
  _code;
18
19
  _retryAt;
19
20
  /** @internal */
@@ -1,7 +1,8 @@
1
+ import { CustomError } from './custom.error.js';
1
2
  /**
2
3
  * An error thrown when running a task on a destroyed rate limiter.
3
4
  */
4
- export declare class RateLimiterDestroyedError extends Error {
5
+ export declare class RateLimiterDestroyedError extends CustomError {
5
6
  constructor();
6
7
  }
7
8
  //# sourceMappingURL=rate-limiter-destroyed.error.d.ts.map
@@ -1,7 +1,8 @@
1
+ import { CustomError } from './custom.error.js';
1
2
  /**
2
3
  * An error thrown when running a task on a destroyed rate limiter.
3
4
  */
4
- export class RateLimiterDestroyedError extends Error {
5
+ export class RateLimiterDestroyedError extends CustomError {
5
6
  constructor() {
6
7
  super('Rate limiter has been destroyed and cannot be used.');
7
8
  }
@@ -71,8 +71,8 @@ export class AbstractRateLimiter {
71
71
  return this._logger.minLevel >= LogLevel.DEBUG;
72
72
  }
73
73
  async _execute(fn, runAt, storeTtlMs, ctx, expiresAt) {
74
- await this._ensureCanExecute(ctx);
75
74
  try {
75
+ await this._ensureCanExecute(ctx);
76
76
  return await this._executor.execute(fn, runAt, {
77
77
  id: ctx.id,
78
78
  key: ctx.key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stimulcross/rate-limiter",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "A collection of client-side rate limiters for Node.js and browsers.",
5
5
  "type": "module",
6
6
  "engines": {