Skip to content

Commit

Permalink
Filter out by error code + invert filtering (#6432)
Browse files Browse the repository at this point in the history
As title

Instance of not working well.

Co-authored-by: Charles Bochet <[email protected]>
  • Loading branch information
thomtrp and charlesBochet authored Jul 29, 2024
1 parent 9b28eeb commit 515d6fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ export const useGraphQLErrorHandlerHook = <
setResult,
}) => {
if (result.errors && result.errors.length > 0) {
const errorsToCapture = result.errors.reduce<BaseGraphQLError[]>(
(acc, error) => {
if (!(error instanceof BaseGraphQLError)) {
error = generateGraphQLErrorFromError(error);
}
const originalErrors = result.errors.map((error) => {
const originalError = error.originalError;

return originalError instanceof BaseGraphQLError
? error.originalError
: generateGraphQLErrorFromError(error);
});

const errorsToCapture = originalErrors.reduce<BaseGraphQLError[]>(
(acc, error) => {
if (shouldCaptureException(error)) {
acc.push(error);
}
Expand All @@ -95,7 +99,7 @@ export const useGraphQLErrorHandlerHook = <
errorsToCapture.map((err, i) => addEventId(err, eventIds?.[i]));
}

const nonCapturedErrors = result.errors.filter(
const nonCapturedErrors = originalErrors.filter(
(error) => !errorsToCapture.includes(error),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export const generateGraphQLErrorFromError = (error: Error) => {
graphqlError.extensions['response'] = error.message;
}

return error;
return graphqlError;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ErrorCode,
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';

export const graphQLErrorCodesToFilter = [
export const graphQLErrorCodesToFilterOut = [
ErrorCode.GRAPHQL_VALIDATION_FAILED,
ErrorCode.UNAUTHENTICATED,
ErrorCode.FORBIDDEN,
Expand All @@ -15,12 +15,13 @@ export const graphQLErrorCodesToFilter = [
];

export const shouldCaptureException = (exception: Error): boolean => {
if (
exception instanceof BaseGraphQLError &&
graphQLErrorCodesToFilter.includes(exception?.extensions?.code)
) {
if (!(exception instanceof BaseGraphQLError)) {
return true;
}

return false;
if (graphQLErrorCodesToFilterOut.includes(exception?.extensions?.code)) {
return false;
}

return true;
};

0 comments on commit 515d6fb

Please sign in to comment.