From e2dc660d180d9d1724888852dd6bb606c5d599a2 Mon Sep 17 00:00:00 2001 From: Weiko Date: Mon, 3 Jun 2024 14:36:03 +0200 Subject: [PATCH] Fix exception handler capturing graphql errors (#5714) Our exception handler has to filter out some errors/exceptions so they are not caught by the ExceptionHandlerDriver (Logged or Sentry for example). This is done for Http errors in the range of 4xx and also makes sure they are converted back to Graphql validation errors. However, graphql validation errors that are already managed by Yoga (with Schema validation) should also be filtered out, this PR should fix that behaviour --- .../src/engine/utils/global-exception-handler.util.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/twenty-server/src/engine/utils/global-exception-handler.util.ts b/packages/twenty-server/src/engine/utils/global-exception-handler.util.ts index 66878862e..326f991bb 100644 --- a/packages/twenty-server/src/engine/utils/global-exception-handler.util.ts +++ b/packages/twenty-server/src/engine/utils/global-exception-handler.util.ts @@ -1,5 +1,7 @@ import { HttpException } from '@nestjs/common'; +import { GraphQLError } from 'graphql'; + import { ExceptionHandlerUser } from 'src/engine/integrations/exception-handler/interfaces/exception-handler-user.interface'; import { @@ -35,6 +37,12 @@ export const handleExceptionAndConvertToGraphQLError = ( }; export const shouldFilterException = (exception: Error): boolean => { + if ( + exception instanceof GraphQLError && + (exception?.extensions?.http?.status ?? 500) < 500 + ) { + return true; + } if (exception instanceof HttpException && exception.getStatus() < 500) { return true; }