import { ExceptionFilter, Catch, ArgumentsHost, BadRequestException } from '@nestjs/common';
import { Response } from 'express';
@Catch(BadRequestException)
export class ValidationFilter implements ExceptionFilter {
catch(exception: BadRequestException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const exceptionResponse = exception.getResponse();
response.status(400).json({
statusCode: 400,
message: 'Validation failed',
errors: (exceptionResponse as any).message || exceptionResponse,
timestamp: new Date().toISOString(),
});
}
}