Fix unhandled exception (#5474)

Solves exception.getStatus is not a function error logs in twenty-server

Catch all errors in order to have no error log at all
This commit is contained in:
martmull
2024-05-21 11:31:03 +02:00
committed by GitHub
parent 0d16051ded
commit 4fcdfbff7d

View File

@ -1,4 +1,9 @@
import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common';
import {
ExceptionFilter,
Catch,
ArgumentsHost,
HttpException,
} from '@nestjs/common';
import { Response } from 'express';
@ -25,6 +30,9 @@ export class ApplyCorsToExceptions implements ExceptionFilter {
'Origin, X-Requested-With, Content-Type, Accept',
);
response.status(exception.getStatus()).json(exception.response);
const status =
exception instanceof HttpException ? exception.getStatus() : 500;
response.status(status).json(exception.response);
}
}