fix(server): pass through 429 status and exempt authenticated requests

This commit is contained in:
neon
2026-01-26 21:18:15 -06:00
parent 1eedc9b255
commit a25ce99a36
3 changed files with 11 additions and 6 deletions
@@ -10,12 +10,17 @@ export class GlobalExceptionFilter implements ExceptionFilter {
const reply = ctx.getResponse<FastifyReply>();
const request = ctx.getRequest<FastifyRequest>();
const status = exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;
const status =
exception instanceof HttpException
? exception.getStatus()
: typeof (exception as any)?.statusCode === 'number'
? (exception as any).statusCode
: HttpStatus.INTERNAL_SERVER_ERROR;
const raw = exception instanceof HttpException ? exception.getResponse() : 'Internal server error';
const message = typeof raw === 'string' ? raw : ((raw as any).message ?? 'An error occurred');
const message = typeof raw === 'string' ? raw : ((raw as any).message ?? (exception as any)?.message ?? 'An error occurred');
if (status === HttpStatus.INTERNAL_SERVER_ERROR) {
if (status >= HttpStatus.INTERNAL_SERVER_ERROR) {
this.logger.error(exception);
}
+1 -1
View File
@@ -5,7 +5,7 @@
{
"idx": 0,
"version": "7",
"when": 1769513599384,
"when": 1769530382856,
"tag": "0000_baseline",
"breakpoints": true
}
+2 -2
View File
@@ -31,11 +31,11 @@ async function bootstrap() {
await app.register(require('@fastify/cookie'));
// Global IP-based rate limit; image/cover endpoints are exempt (high volume, cheap reads)
// Rate limit unauthenticated requests only (brute-force protection on public endpoints)
await app.register(require('@fastify/rate-limit'), {
max: 100,
timeWindow: '1 minute',
allowList: (req: { url: string }) => /^\/api\/books\/\d+\/(thumbnail|cover)/.test(req.url),
allowList: (req: { cookies?: { access_token?: string } }) => !!req.cookies?.access_token,
});
if (process.env.NODE_ENV !== 'production') {