The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Stop reporting contact creation duplicate key conflicts to Sentry (#24355)
Thomas Trompettede9bd36f37f4
diff --git a/packages/twenty-server/src/modules/contact-creation-manager/services/create-company-and-contact.service.ts b/packages/twenty-server/src/modules/contact-creation-manager/services/create-company-and-contact.service.tsindex 465e6c6e1e0..a8dede6ae75 100644--- a/packages/twenty-server/src/modules/contact-creation-manager/services/create-company-and-contact.service.ts+++ b/packages/twenty-server/src/modules/contact-creation-manager/services/create-company-and-contact.service.ts@@ -17,6 +17,10 @@ import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handlimport { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';import { type ConnectedAccountEntity } from 'src/engine/metadata-modules/connected-account/entities/connected-account.entity';+import {+ TwentyORMException,+ TwentyORMExceptionCode,+} from 'src/engine/twenty-orm/exceptions/twenty-orm.exception';import { GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager';import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/contact-creation-manager/constants/contacts-creation-batch-size.constant';@@ -33,6 +37,10 @@ import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/staimport { computeDisplayName } from 'src/utils/compute-display-name';import { isWorkDomain, isWorkEmail } from 'src/utils/is-work-email';+const isDuplicateEntryError = (error: unknown) =>+ error instanceof TwentyORMException &&+ error.code === TwentyORMExceptionCode.DUPLICATE_ENTRY_DETECTED;+@Injectable()export class CreateCompanyAndPersonService {private readonly logger = new Logger(CreateCompanyAndPersonService.name);@@ -224,6 +232,13 @@ export class CreateCompanyAndPersonService {accountOwner,);} catch (error) {+ // Concurrent imports for the same workspace can insert the same company+ // domain or person email, and the loser hits the unique index. The+ // record it wanted exists either way.+ if (isDuplicateEntryError(error)) {+ continue;+ }+this.exceptionHandlerService.captureExceptions([error], {workspace: {id: workspaceId,