Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out by error code + invert filtering #6432

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
Loading