diff --git a/packages/session-replay-browser/src/events/events-idb-store.ts b/packages/session-replay-browser/src/events/events-idb-store.ts index 70e63c587..8986d9d86 100644 --- a/packages/session-replay-browser/src/events/events-idb-store.ts +++ b/packages/session-replay-browser/src/events/events-idb-store.ts @@ -127,11 +127,15 @@ export class SessionReplayEventsIDBStore implements AmplitudeSessionReplayEvents } async initialize(type: EventType, sessionId?: number) { - const dbSuffix = type === 'replay' ? '' : `_${type}`; - const dbName = `${this.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`; - this.db = await createStore(dbName); - this.timeAtLastSplit = Date.now(); // Initialize this so we have a point of comparison when events are recorded - await this.transitionFromKeyValStore(sessionId); + try { + const dbSuffix = type === 'replay' ? '' : `_${type}`; + const dbName = `${this.apiKey.substring(0, 10)}_amp_session_replay_events${dbSuffix}`; + this.db = await createStore(dbName); + this.timeAtLastSplit = Date.now(); // Initialize this so we have a point of comparison when events are recorded + await this.transitionFromKeyValStore(sessionId); + } catch (e) { + this.loggerProvider.warn(`${STORAGE_FAILURE}: ${e as string}`); + } } /** diff --git a/packages/session-replay-browser/test/events-idb-store.test.ts b/packages/session-replay-browser/test/events-idb-store.test.ts index b52431002..533d1434a 100644 --- a/packages/session-replay-browser/test/events-idb-store.test.ts +++ b/packages/session-replay-browser/test/events-idb-store.test.ts @@ -53,6 +53,18 @@ describe('SessionReplayEventsIDBStore', () => { await eventsStorage.initialize('replay'); expect(EventsIDBStore.createStore).toHaveBeenCalledWith('static_key_amp_session_replay_events'); }); + + test('should catch errors', async () => { + const mockCreateStore = jest.spyOn(EventsIDBStore, 'createStore'); + const errorMessage = 'Failed to create store'; + + mockCreateStore.mockRejectedValue(new Error(errorMessage)); + + const eventsStorage = new SessionReplayEventsIDBStore({ apiKey, loggerProvider: mockLoggerProvider }); + + await eventsStorage.initialize('replay'); + expect(mockLoggerProvider.warn).toHaveBeenCalled(); + }); }); describe('getSequencesToSend', () => {