mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-25 04:55:30 +03:00
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:
parent
9b28eebfd6
commit
515d6fb1c5
@ -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),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -14,5 +14,5 @@ export const generateGraphQLErrorFromError = (error: Error) => {
|
|||||||
graphqlError.extensions['response'] = error.message;
|
graphqlError.extensions['response'] = error.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return graphqlError;
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user