mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-20 06:43:36 +02:00
add mana core
This commit is contained in:
parent
ce71db2fc0
commit
754e87ebc0
112 changed files with 34765 additions and 548 deletions
31
packages/shared-errors/src/errors/rate-limit-error.ts
Normal file
31
packages/shared-errors/src/errors/rate-limit-error.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { ErrorCode } from '../types/error-codes';
|
||||
import { AppError } from './app-error';
|
||||
|
||||
/**
|
||||
* Error for rate limiting.
|
||||
* HTTP Status: 429 Too Many Requests
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Basic rate limit error
|
||||
* return err(new RateLimitError());
|
||||
*
|
||||
* // With retry-after information
|
||||
* return err(new RateLimitError('Too many requests', 60));
|
||||
* // Client should wait 60 seconds before retrying
|
||||
* ```
|
||||
*/
|
||||
export class RateLimitError extends AppError {
|
||||
/** Seconds to wait before retrying (if known) */
|
||||
readonly retryAfter?: number;
|
||||
|
||||
constructor(message = 'Rate limit exceeded', retryAfter?: number) {
|
||||
super({
|
||||
code: ErrorCode.RATE_LIMIT_EXCEEDED,
|
||||
message,
|
||||
context: retryAfter ? { retryAfter } : {},
|
||||
});
|
||||
this.name = 'RateLimitError';
|
||||
this.retryAfter = retryAfter;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue