Skip to content

Commit

Permalink
Fix unhandled exception (twentyhq#5474)
Browse files Browse the repository at this point in the history
Solves exception.getStatus is not a function error logs in twenty-server

Catch all errors in order to have no error log at all
  • Loading branch information
martmull authored May 21, 2024
1 parent 0d16051 commit 4fcdfbf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/twenty-server/src/utils/apply-cors-to-exceptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common';
import {
ExceptionFilter,
Catch,
ArgumentsHost,
HttpException,
} from '@nestjs/common';

import { Response } from 'express';

Expand All @@ -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);
}
}

0 comments on commit 4fcdfbf

Please sign in to comment.