The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Filter out by error code + invert filtering (#6432)
Thomas Trompette515d6fb1c5fa
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.tsindex 0f98cdcfdb4..ef47046fe5b 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<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),);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.tsindex 35201e31bd7..ab351b332e2 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.tsindex f801e9be71a..60ed62245f3 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;};