Skip to content

Commit e0820cf

Browse files
authored
fix(replay): Fix onError callback (#14002)
This fixes the `onError` callback added in #13721 -- the option itself was not being propagated to the replay options.
1 parent fe639f4 commit e0820cf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/replay-internal/src/integration.ts

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class Replay implements Integration {
114114

115115
beforeAddRecordingEvent,
116116
beforeErrorSampling,
117+
onError,
117118
}: ReplayConfiguration = {}) {
118119
this.name = Replay.id;
119120

@@ -183,6 +184,7 @@ export class Replay implements Integration {
183184
networkResponseHeaders: _getMergedNetworkHeaders(networkResponseHeaders),
184185
beforeAddRecordingEvent,
185186
beforeErrorSampling,
187+
onError,
186188

187189
_experiments,
188190
};

packages/replay-internal/test/integration/sendReplayEvent.test.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('Integration | sendReplayEvent', () => {
2828
let mockTransportSend: MockTransportSend;
2929
let mockSendReplayRequest: MockInstance<any>;
3030
let domHandler: DomHandler;
31+
const onError: () => void = vi.fn();
3132
const { record: mockRecord } = mockRrweb();
3233

3334
beforeAll(async () => {
@@ -44,6 +45,7 @@ describe('Integration | sendReplayEvent', () => {
4445
_experiments: {
4546
captureExceptions: true,
4647
},
48+
onError,
4749
},
4850
}));
4951

@@ -54,6 +56,7 @@ describe('Integration | sendReplayEvent', () => {
5456
});
5557

5658
beforeEach(() => {
59+
vi.clearAllMocks();
5760
vi.setSystemTime(new Date(BASE_TIMESTAMP));
5861
mockRecord.takeFullSnapshot.mockClear();
5962
mockTransportSend.mockClear();
@@ -357,8 +360,9 @@ describe('Integration | sendReplayEvent', () => {
357360
expect(replay).not.toHaveLastSentReplay();
358361
});
359362

360-
it('fails to upload data and hits retry max and stops', async () => {
363+
it('fails to upload data, hits retry max, stops, and calls `onError` with the error', async () => {
361364
const TEST_EVENT = getTestEventIncremental({ timestamp: BASE_TIMESTAMP });
365+
const ERROR = new Error('Something bad happened');
362366

363367
const spyHandleException = vi.spyOn(SentryCore, 'captureException');
364368

@@ -369,7 +373,7 @@ describe('Integration | sendReplayEvent', () => {
369373

370374
// fail all requests
371375
mockSendReplayRequest.mockImplementation(async () => {
372-
throw new Error('Something bad happened');
376+
throw ERROR;
373377
});
374378
mockRecord._emitter(TEST_EVENT);
375379

@@ -406,6 +410,8 @@ describe('Integration | sendReplayEvent', () => {
406410
// Replay has stopped, no session should exist
407411
expect(replay.session).toBe(undefined);
408412
expect(replay.isEnabled()).toBe(false);
413+
expect(onError).toHaveBeenCalledTimes(5);
414+
expect(onError).toHaveBeenCalledWith(ERROR);
409415

410416
// Events are ignored now, because we stopped
411417
mockRecord._emitter(TEST_EVENT);

0 commit comments

Comments
 (0)