@@ -5,6 +5,7 @@ import { randomUUID } from 'node:crypto';
5
5
import { captureException } from '@sentry/node' ;
6
6
import { ZodError } from 'zod' ;
7
7
import { InternalServerErrorException } from '@nestjs/common/exceptions/internal-server-error.exception' ;
8
+ import { ThrottlerException } from '@nestjs/throttler' ;
8
9
import { ErrorDto , ValidationErrorDto } from './error-dto' ;
9
10
10
11
const ERROR_MSG_500 = `Internal server error, contact support and provide them with the errorId` ;
@@ -56,6 +57,10 @@ export class AllExceptionsFilter implements ExceptionFilter {
56
57
}
57
58
58
59
private buildErrorResponse ( exception : unknown , request : Request ) : ErrorDto {
60
+ if ( exception instanceof HttpException && exception . name === 'ThrottlerException' ) {
61
+ return this . handlerThrotlerException ( request ) ;
62
+ }
63
+
59
64
if ( exception instanceof ZodError ) {
60
65
return this . handleZod ( exception , request ) ;
61
66
}
@@ -150,8 +155,11 @@ export class AllExceptionsFilter implements ExceptionFilter {
150
155
151
156
return { ...errorDto , errors : { general : { messages : exception . response . message , value : 'No Value Recorded' } } } ;
152
157
}
153
- }
154
158
159
+ private handlerThrotlerException ( request : Request ) {
160
+ return this . buildErrorDto ( request , HttpStatus . TOO_MANY_REQUESTS , 'API rate limit exceeded' , { } ) ;
161
+ }
162
+ }
155
163
function hasMessage ( response : unknown ) : response is { message : string } {
156
164
return typeof response === 'object' && response !== null && 'message' in response ;
157
165
}
0 commit comments