Skip to content

Commit 87971da

Browse files
committed
fix excpetion mapper
1 parent 805400c commit 87971da

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

apps/api/src/exception-filter.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { randomUUID } from 'node:crypto';
55
import { captureException } from '@sentry/node';
66
import { ZodError } from 'zod';
77
import { InternalServerErrorException } from '@nestjs/common/exceptions/internal-server-error.exception';
8+
import { ThrottlerException } from '@nestjs/throttler';
89
import { ErrorDto, ValidationErrorDto } from './error-dto';
910

1011
const ERROR_MSG_500 = `Internal server error, contact support and provide them with the errorId`;
@@ -56,6 +57,10 @@ export class AllExceptionsFilter implements ExceptionFilter {
5657
}
5758

5859
private buildErrorResponse(exception: unknown, request: Request): ErrorDto {
60+
if (exception instanceof HttpException && exception.name === 'ThrottlerException') {
61+
return this.handlerThrotlerException(request);
62+
}
63+
5964
if (exception instanceof ZodError) {
6065
return this.handleZod(exception, request);
6166
}
@@ -150,8 +155,11 @@ export class AllExceptionsFilter implements ExceptionFilter {
150155

151156
return { ...errorDto, errors: { general: { messages: exception.response.message, value: 'No Value Recorded' } } };
152157
}
153-
}
154158

159+
private handlerThrotlerException(request: Request) {
160+
return this.buildErrorDto(request, HttpStatus.TOO_MANY_REQUESTS, 'API rate limit exceeded', {});
161+
}
162+
}
155163
function hasMessage(response: unknown): response is { message: string } {
156164
return typeof response === 'object' && response !== null && 'message' in response;
157165
}

0 commit comments

Comments
 (0)