diff --git a/packages/twenty-server/src/engine/core-modules/graphql/hooks/use-graphql-error-handler.hook.ts b/packages/twenty-server/src/engine/core-modules/graphql/hooks/use-graphql-error-handler.hook.ts index 0f98cdcfdb..ef47046fe5 100644 --- a/packages/twenty-server/src/engine/core-modules/graphql/hooks/use-graphql-error-handler.hook.ts +++ b/packages/twenty-server/src/engine/core-modules/graphql/hooks/use-graphql-error-handler.hook.ts @@ -64,12 +64,16 @@ export const useGraphQLErrorHandlerHook = < setResult, }) => { if (result.errors && result.errors.length > 0) { - const errorsToCapture = result.errors.reduce( - (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( + (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), ); diff --git a/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts b/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts index 35201e31bd..ab351b332e 100644 --- a/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts +++ b/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts @@ -14,5 +14,5 @@ export const generateGraphQLErrorFromError = (error: Error) => { graphqlError.extensions['response'] = error.message; } - return error; + return graphqlError; }; diff --git a/packages/twenty-server/src/engine/core-modules/graphql/utils/should-capture-exception.util.ts b/packages/twenty-server/src/engine/core-modules/graphql/utils/should-capture-exception.util.ts index f801e9be71..60ed62245f 100644 --- a/packages/twenty-server/src/engine/core-modules/graphql/utils/should-capture-exception.util.ts +++ b/packages/twenty-server/src/engine/core-modules/graphql/utils/should-capture-exception.util.ts @@ -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; };