Filter out by error code + invert filtering (#6432)

As title

Instance of not working well.

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Thomas Trompette 2024-07-29 16:18:23 +02:00 committed by GitHub
parent 9b28eebfd6
commit 515d6fb1c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 13 deletions

View File

@ -64,12 +64,16 @@ export const useGraphQLErrorHandlerHook = <
setResult, setResult,
}) => { }) => {
if (result.errors && result.errors.length > 0) { if (result.errors && result.errors.length > 0) {
const errorsToCapture = result.errors.reduce<BaseGraphQLError[]>( const originalErrors = result.errors.map((error) => {
(acc, error) => { const originalError = error.originalError;
if (!(error instanceof BaseGraphQLError)) {
error = generateGraphQLErrorFromError(error);
}
return originalError instanceof BaseGraphQLError
? error.originalError
: generateGraphQLErrorFromError(error);
});
const errorsToCapture = originalErrors.reduce<BaseGraphQLError[]>(
(acc, error) => {
if (shouldCaptureException(error)) { if (shouldCaptureException(error)) {
acc.push(error); acc.push(error);
} }
@ -95,7 +99,7 @@ export const useGraphQLErrorHandlerHook = <
errorsToCapture.map((err, i) => addEventId(err, eventIds?.[i])); errorsToCapture.map((err, i) => addEventId(err, eventIds?.[i]));
} }
const nonCapturedErrors = result.errors.filter( const nonCapturedErrors = originalErrors.filter(
(error) => !errorsToCapture.includes(error), (error) => !errorsToCapture.includes(error),
); );

View File

@ -14,5 +14,5 @@ export const generateGraphQLErrorFromError = (error: Error) => {
graphqlError.extensions['response'] = error.message; graphqlError.extensions['response'] = error.message;
} }
return error; return graphqlError;
}; };

View File

@ -3,7 +3,7 @@ import {
ErrorCode, ErrorCode,
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util'; } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
export const graphQLErrorCodesToFilter = [ export const graphQLErrorCodesToFilterOut = [
ErrorCode.GRAPHQL_VALIDATION_FAILED, ErrorCode.GRAPHQL_VALIDATION_FAILED,
ErrorCode.UNAUTHENTICATED, ErrorCode.UNAUTHENTICATED,
ErrorCode.FORBIDDEN, ErrorCode.FORBIDDEN,
@ -15,12 +15,13 @@ export const graphQLErrorCodesToFilter = [
]; ];
export const shouldCaptureException = (exception: Error): boolean => { export const shouldCaptureException = (exception: Error): boolean => {
if ( if (!(exception instanceof BaseGraphQLError)) {
exception instanceof BaseGraphQLError &&
graphQLErrorCodesToFilter.includes(exception?.extensions?.code)
) {
return true; return true;
} }
return false; if (graphQLErrorCodesToFilterOut.includes(exception?.extensions?.code)) {
return false;
}
return true;
}; };