From 030cebaa6b67a8d76697fa2f205d83648364764b Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 30 May 2023 00:53:17 +0530 Subject: [PATCH] fix: handle UnprocessableEntity exception Signed-off-by: Pranav C --- .../src/filters/global-exception/global-exception.filter.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts index ac9b6e5692..7f8ac8adc5 100644 --- a/packages/nocodb/src/filters/global-exception/global-exception.filter.ts +++ b/packages/nocodb/src/filters/global-exception/global-exception.filter.ts @@ -8,6 +8,7 @@ import { NotFound, NotImplemented, Unauthorized, + UnprocessableEntity, } from '../../helpers/catchError'; import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'; import type { Response } from 'express'; @@ -15,6 +16,7 @@ import type { Response } from 'express'; @Catch() export class GlobalExceptionFilter implements ExceptionFilter { private logger = new Logger(GlobalExceptionFilter.name); + catch(exception: any, host: ArgumentsHost) { const ctx = host.switchToHttp(); const response = ctx.getResponse(); @@ -58,6 +60,8 @@ export class GlobalExceptionFilter implements ExceptionFilter { return response .status(400) .json({ msg: exception.message, errors: exception.errors }); + } else if (exception instanceof UnprocessableEntity) { + return response.status(422).json({ msg: exception.message }); } // handle different types of exceptions