Browse Source

fix: handle UnprocessableEntity exception

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5901/head
Pranav C 1 year ago
parent
commit
030cebaa6b
  1. 4
      packages/nocodb/src/filters/global-exception/global-exception.filter.ts

4
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<Response>();
@ -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

Loading…
Cancel
Save