sveltekit-rate-limiter
sveltekit-rate-limiter copied to clipboard
Feature request: Expose rate-limit reason
For debugging/logging/testing, it would be valuable to know the reason for being rate limited.
For example:
const status = await limiter.check(event);
if (status.limited) {
console.warn(
'Rate limit activated:',
event.getClientAddress(),
status.limitedBy // <-- new, expose which limiter blocked the request
);
let response = new Response(
`You are being rate limited. Please try after ${status.retryAfter} seconds.`,
{
status: 429,
headers: { 'Retry-After': status.retryAfter.toString() }
}
);
return response;
}
Proposed limitedBy property would have a type signature of something like this:
type LimitedBy = "IP" | "IPUA" | "cookies" | `plugins[${number}]` | undefined