Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/replay/src/util/sendReplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ export async function sendReplay(
// If an error happened here, it's likely that uploading the attachment
// failed, we'll can retry with the same events payload
if (retryConfig.count >= RETRY_MAX_COUNT) {
throw new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);
const error = new Error(`${UNABLE_TO_SEND_REPLAY} - max retries exceeded`);

try {
// In case browsers don't allow this property to be writable
// @ts-ignore This needs lib es2022 and newer
error.cause = err;
} catch {
// nothing to do
}

throw error;
}

// will retry in intervals of 5, 10, 30
Expand Down
13 changes: 11 additions & 2 deletions packages/replay/src/util/sendReplayRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,17 @@ export async function sendReplayRequest({

try {
response = await transport.send(envelope);
} catch {
throw new Error(UNABLE_TO_SEND_REPLAY);
} catch (err) {
const error = new Error(UNABLE_TO_SEND_REPLAY);

try {
// In case browsers don't allow this property to be writable
// @ts-ignore This needs lib es2022 and newer
error.cause = err;
} catch {
// nothing to do
}
throw error;
}

// TODO (v8): we can remove this guard once transport.send's type signature doesn't include void anymore
Expand Down
5 changes: 5 additions & 0 deletions packages/replay/test/integration/sendReplayEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ describe('Integration | sendReplayEvent', () => {
expect(spyHandleException).toHaveBeenCalledTimes(5);
expect(spyHandleException).toHaveBeenLastCalledWith(new Error('Unable to send Replay - max retries exceeded'));

const spyHandleExceptionCall = spyHandleException.mock.calls;
expect(spyHandleExceptionCall[spyHandleExceptionCall.length - 1][0].cause.message).toEqual(
'Something bad happened',
);

// No activity has occurred, session's last activity should remain the same
expect(replay.session?.lastActivity).toBe(BASE_TIMESTAMP);

Expand Down