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
This commit is contained in:
Weiko 2024-06-03 14:36:03 +02:00 committed by GitHub
parent 2d12984db4
commit e2dc660d18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}