From 025d4f606b3b04d88c8bb2710fd2e567bf639d22 Mon Sep 17 00:00:00 2001 From: Moumita <36885121+MoumitaM@users.noreply.github.com> Date: Mon, 22 Jul 2024 17:09:36 +0530 Subject: [PATCH] fix: prevent default rejection handling (#1791) --- .../analytics-js/src/services/ErrorHandler/ErrorHandler.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts b/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts index 3f53509fc..14417c5ab 100644 --- a/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts +++ b/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts @@ -67,6 +67,10 @@ class ErrorHandler implements IErrorHandler { (globalThis as typeof window).addEventListener( 'unhandledrejection', (event: PromiseRejectionEvent) => { + if (!(event.reason instanceof Error)) { + // Prevent the default handling by the browser + event.preventDefault(); + } this.onError(event, undefined, undefined, undefined, ErrorType.UNHANDLEDREJECTION); }, );