diff --git a/packages/analytics-js/__tests__/services/ErrorHandler/ErrorHandler.test.ts b/packages/analytics-js/__tests__/services/ErrorHandler/ErrorHandler.test.ts index ac7f315a49..19d7acb7f6 100644 --- a/packages/analytics-js/__tests__/services/ErrorHandler/ErrorHandler.test.ts +++ b/packages/analytics-js/__tests__/services/ErrorHandler/ErrorHandler.test.ts @@ -117,12 +117,18 @@ describe('ErrorHandler', () => { expect(defaultLogger.error).toHaveBeenCalledTimes(0); }); - it('should skip handled errors if they are not originated from the sdk', () => { + it('should not skip handled errors even if they are not originated from the sdk', () => { + // Enable error reporting + state.reporting.isErrorReportingEnabled.value = true; + // For this error, the stacktrace would not contain the sdk file names errorHandlerInstance.onError(new Error('dummy error')); - // It should not be logged to the console - expect(defaultLogger.error).toHaveBeenCalledTimes(0); + // It should be reported to the metrics service + expect(defaultHttpClient.getAsyncData).toHaveBeenCalledTimes(1); + + // It should be logged to the console + expect(defaultLogger.error).toHaveBeenCalledTimes(1); }); it('should not log unhandled errors to the console', () => { diff --git a/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts b/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts index aedc008077..ed3d0414ed 100644 --- a/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts +++ b/packages/analytics-js/src/services/ErrorHandler/ErrorHandler.ts @@ -75,9 +75,13 @@ class ErrorHandler implements IErrorHandler { const isSdkDispatched = stacktrace.includes(MANUAL_ERROR_IDENTIFIER); // Filter errors that are not originated in the SDK. - // In case of NPM installations, the errors from the SDK cannot be identified + // In case of NPM installations, the unhandled errors from the SDK cannot be identified // and will NOT be reported unless they occur in plugins or integrations. - if (!isSdkDispatched && !isSDKError(bsException)) { + if ( + !isSdkDispatched && + !isSDKError(bsException) && + errorType !== ErrorType.HANDLEDEXCEPTION + ) { return; }