mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-23 20:13:21 +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,
|
||||
}) => {
|
||||
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);
|
||||
}
|
||||
@ -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),
|
||||
);
|
||||
|
||||
|
@ -14,5 +14,5 @@ export const generateGraphQLErrorFromError = (error: Error) => {
|
||||
graphqlError.extensions['response'] = error.message;
|
||||
}
|
||||
|
||||
return error;
|
||||
return graphqlError;
|
||||
};
|
||||
|
@ -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,
|
||||
@ -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…
Reference in New Issue
Block a user