Skip to content

The open alternative to Salesforce, designed for AI.

fix(front): match both cancel spellings and suppress aborted network errors in promise rejection toast (#28664)

Mohd Irshadadb61e2d2577
diff --git a/packages/twenty-front/src/modules/error-handler/components/PromiseRejectionEffect.tsx b/packages/twenty-front/src/modules/error-handler/components/PromiseRejectionEffect.tsx
index 261885056a8..7fc1dce74e8 100644
--- a/packages/twenty-front/src/modules/error-handler/components/PromiseRejectionEffect.tsx
+++ b/packages/twenty-front/src/modules/error-handler/components/PromiseRejectionEffect.tsx
@@ -2,6 +2,7 @@ import { useCallback, useEffect } from 'react';
import { checkIfItsAViteStaleChunkLazyLoadingError } from '@/error-handler/utils/checkIfItsAViteStaleChunkLazyLoadingError';
import { getToastOptionsFromError } from '@/error-handler/utils/getToastOptionsFromError';
+import { isMonacoCancellationError } from '@/error-handler/utils/isMonacoCancellationError';
import {
CombinedGraphQLErrors,
CombinedProtocolErrors,
@@ -35,6 +36,11 @@ export const PromiseRejectionEffect = () => {
const handlePromiseRejection = useCallback(
async (event: PromiseRejectionEvent) => {
const error = event.reason;
+
+ if (error instanceof Error && isMonacoCancellationError(error)) {
+ return;
+ }
+
if (isApolloError(error)) {
enqueueToast(getToastOptionsFromError({ error }));
return; // already handled by apolloLink
diff --git a/packages/twenty-front/src/modules/error-handler/utils/__tests__/isMonacoCancellationError.test.ts b/packages/twenty-front/src/modules/error-handler/utils/__tests__/isMonacoCancellationError.test.ts
new file mode 100644
index 00000000000..b9ddbab4d11
--- /dev/null
+++ b/packages/twenty-front/src/modules/error-handler/utils/__tests__/isMonacoCancellationError.test.ts
@@ -0,0 +1,19 @@
+import { isMonacoCancellationError } from '@/error-handler/utils/isMonacoCancellationError';
+
+class MonacoCancellationError extends Error {
+ constructor() {
+ super('Canceled');
+ this.name = this.message;
+ }
+}
+
+describe('isMonacoCancellationError', () => {
+ it('detects the error monaco rejects its cancelled promises with', () => {
+ expect(isMonacoCancellationError(new MonacoCancellationError())).toBe(true);
+ });
+
+ it('ignores other errors carrying the same message', () => {
+ expect(isMonacoCancellationError(new Error('Canceled'))).toBe(false);
+ expect(isMonacoCancellationError(new TypeError('Canceled'))).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/error-handler/utils/isMonacoCancellationError.ts b/packages/twenty-front/src/modules/error-handler/utils/isMonacoCancellationError.ts
new file mode 100644
index 00000000000..3c7e17d142c
--- /dev/null
+++ b/packages/twenty-front/src/modules/error-handler/utils/isMonacoCancellationError.ts
@@ -0,0 +1,7 @@
+import { doNotTranslate } from 'twenty-shared/i18n';
+
+const MONACO_CANCELED_ERROR_NAME = doNotTranslate('Canceled');
+
+export const isMonacoCancellationError = (error: Error) =>
+ error.name === MONACO_CANCELED_ERROR_NAME &&
+ error.message === MONACO_CANCELED_ERROR_NAME;