@adonisjs/limiter
Version:
Rate limiting package for AdonisJS framework
73 lines (72 loc) • 2.04 kB
TypeScript
import { Exception } from '@adonisjs/core/exceptions';
import type { HttpContext } from '@adonisjs/core/http';
import type { LimiterResponse } from './response.js';
/**
* Throttle exception is raised when the user has exceeded
* the number of requests allowed during a given duration
*/
export declare class ThrottleException extends Exception {
response: LimiterResponse;
message: string;
status: number;
code: string;
/**
* Error identifier to lookup translation message
*/
identifier: string;
/**
* The response headers to set when converting exception
* to response
*/
headers?: {
[name: string]: any;
};
/**
* Translation identifier to use for creating throttle
* response.
*/
translation?: {
identifier: string;
data?: Record<string, any>;
};
constructor(response: LimiterResponse, options?: ErrorOptions & {
code?: string;
status?: number;
});
/**
* Returns the default headers for the response
*/
getDefaultHeaders(): {
[K: string]: any;
};
/**
* Returns the message to be sent in the HTTP response.
* Feel free to override this method and return a custom
* response.
*/
getResponseMessage(ctx: HttpContext): string;
/**
* Update the default error message
*/
setMessage(message: string): this;
/**
* Update the default error status code
*/
setStatus(status: number): this;
/**
* Define custom response headers. Existing headers will
* be removed
*/
setHeaders(headers: {
[name: string]: any;
}): this;
/**
* Define the translation identifier for the throttle response
*/
t(identifier: string, data?: Record<string, any>): this;
/**
* Converts the throttle exception to an HTTP response
*/
handle(error: ThrottleException, ctx: HttpContext): Promise<void>;
}
export declare const E_TOO_MANY_REQUESTS: typeof ThrottleException;