diff --git a/CHANGELOG.md b/CHANGELOG.md index 85dd5f063e..4d6d368aba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v13.4.0...dev) + +### Fixed + +- Replace thrown errors with logs ([#1220](https://github.com/Instabug/Instabug-React-Native/pull/1220)) + ## [13.4.0](https://github.com/Instabug/Instabug-React-Native/compare/v13.3.0...v13.4.0) (October 2, 2024) ### Added diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index 29ff1d27c9..1d528fba94 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -25,6 +25,7 @@ import * as NetworkLogger from './NetworkLogger'; import { captureUnhandledRejections } from '../utils/UnhandledRejectionTracking'; import type { ReproConfig } from '../models/ReproConfig'; import type { FeatureFlag } from '../models/FeatureFlag'; +import InstabugConstants from '../utils/InstabugConstants'; let _currentScreen: string | null = null; let _lastScreen: string | null = null; @@ -381,7 +382,8 @@ export const setReproStepsConfig = (config: ReproConfig) => { */ export const setUserAttribute = (key: string, value: string) => { if (!key || typeof key !== 'string' || typeof value !== 'string') { - throw new TypeError('Invalid param, Expected String'); + console.error(InstabugConstants.SET_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE); + return; } NativeInstabug.setUserAttribute(key, value); }; @@ -404,7 +406,9 @@ export const getUserAttribute = async (key: string): Promise => { */ export const removeUserAttribute = (key: string) => { if (!key || typeof key !== 'string') { - throw new TypeError('Invalid param, Expected String'); + console.error(InstabugConstants.REMOVE_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE); + + return; } NativeInstabug.removeUserAttribute(key); }; diff --git a/src/utils/InstabugConstants.ts b/src/utils/InstabugConstants.ts index 59bdb2324f..6d117d9871 100644 --- a/src/utils/InstabugConstants.ts +++ b/src/utils/InstabugConstants.ts @@ -7,6 +7,10 @@ const InstabugConstants = { 'The response body has not been logged because it exceeds the maximum size of 10 Kb', MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE: 'The request body has not been logged because it exceeds the maximum size of 10 Kb', + SET_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE: + 'IBG-RN: Expected key and value passed to setUserAttribute to be of type string', + REMOVE_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE: + 'IBG-RN: Expected key and value passed to removeUserAttribute to be of type string', }; export default InstabugConstants; diff --git a/test/modules/APM.spec.ts b/test/modules/APM.spec.ts index d11cadf32b..cf932d25cf 100644 --- a/test/modules/APM.spec.ts +++ b/test/modules/APM.spec.ts @@ -62,7 +62,6 @@ describe('APM Module', () => { it("should throw an error if native startExecutionTrace didn't return an ID", async () => { mocked(NativeAPM).startExecutionTrace.mockResolvedValueOnce(null); - const promise = APM.startExecutionTrace('trace'); await expect(promise).rejects.toThrowError(/trace "trace" wasn't created/i); diff --git a/test/modules/Instabug.spec.ts b/test/modules/Instabug.spec.ts index fdc1b91b24..46b4b208e1 100644 --- a/test/modules/Instabug.spec.ts +++ b/test/modules/Instabug.spec.ts @@ -23,6 +23,7 @@ import { } from '../../src/utils/Enums'; import InstabugUtils from '../../src/utils/InstabugUtils'; import type { FeatureFlag } from '../../src/models/FeatureFlag'; +import InstabugConstants from '../../src/utils/InstabugConstants'; describe('Instabug Module', () => { beforeEach(() => { @@ -640,10 +641,13 @@ describe('Instabug Module', () => { [{}, 'value'], ['key', []], ])("should fail if key and value aren't strings when calling setUserAttribute", (key, value) => { - // @ts-ignore - expect(() => Instabug.setUserAttribute(key, value)).toThrow(TypeError); + const logSpy = jest.spyOn(console, 'error'); + // @ts-ignore + Instabug.setUserAttribute(key, value); expect(NativeInstabug.setUserAttribute).not.toBeCalled(); + expect(logSpy).toHaveBeenCalledWith(InstabugConstants.SET_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE); + logSpy.mockRestore(); }); it('should call the native method setUserAttribute', () => { @@ -676,14 +680,17 @@ describe('Instabug Module', () => { expect(NativeInstabug.removeUserAttribute).toBeCalledWith(key); }); - it.each([null, 1, {}])( - "should fail if key isn't a string when calling removeUserAttribute", - (key) => { - // @ts-ignore - expect(() => Instabug.removeUserAttribute(key)).toThrow(TypeError); - expect(NativeInstabug.removeUserAttribute).not.toBeCalled(); - }, - ); + it.each([[null]])("should fail if key isn't a string when calling removeUserAttribute", (key) => { + const logSpy = jest.spyOn(console, 'error'); + + // @ts-ignore + Instabug.removeUserAttribute(key); + expect(NativeInstabug.removeUserAttribute).not.toBeCalled(); + expect(logSpy).toHaveBeenCalledWith( + InstabugConstants.REMOVE_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE, + ); + logSpy.mockRestore(); + }); it('should call native method getAllUserAttributes', async () => { const expected = { type: 'guest' };