Skip to content

Commit

Permalink
fix(replay): Fix onError callback
Browse files Browse the repository at this point in the history
This fixes the `onError` callback added in #13721 -- the option itself was not being propagated to the replay options.
  • Loading branch information
billyvg committed Oct 16, 2024
1 parent 8782af8 commit 7ca6635
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/replay-internal/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class Replay implements Integration {

beforeAddRecordingEvent,
beforeErrorSampling,
onError,
}: ReplayConfiguration = {}) {
this.name = Replay.id;

Expand Down Expand Up @@ -183,6 +184,7 @@ export class Replay implements Integration {
networkResponseHeaders: _getMergedNetworkHeaders(networkResponseHeaders),
beforeAddRecordingEvent,
beforeErrorSampling,
onError,

_experiments,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Integration | sendReplayEvent', () => {
let mockTransportSend: MockTransportSend;
let mockSendReplayRequest: MockInstance<any>;
let domHandler: DomHandler;
const onError: () => void = vi.fn();
const { record: mockRecord } = mockRrweb();

beforeAll(async () => {
Expand All @@ -44,6 +45,7 @@ describe('Integration | sendReplayEvent', () => {
_experiments: {
captureExceptions: true,
},
onError,
},
}));

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

beforeEach(() => {
vi.clearAllMocks();
vi.setSystemTime(new Date(BASE_TIMESTAMP));
mockRecord.takeFullSnapshot.mockClear();
mockTransportSend.mockClear();
Expand Down Expand Up @@ -357,8 +360,9 @@ describe('Integration | sendReplayEvent', () => {
expect(replay).not.toHaveLastSentReplay();
});

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

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

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

// fail all requests
mockSendReplayRequest.mockImplementation(async () => {
throw new Error('Something bad happened');
throw ERROR;
});
mockRecord._emitter(TEST_EVENT);

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

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

0 comments on commit 7ca6635

Please sign in to comment.