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
32 changes: 16 additions & 16 deletions packages/replay-internal/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ export class ReplayContainer implements ReplayContainerInterface {
return this._options;
}

/** A wrapper to conditionally capture exceptions. */
public handleException(error: unknown): void {
DEBUG_BUILD && logger.error('[Replay]', error);

if (DEBUG_BUILD && this._options._experiments && this._options._experiments.captureExceptions) {
captureException(error);
}
}

/**
* Initializes the plugin based on sampling configuration. Should not be
* called outside of constructor.
Expand All @@ -264,7 +273,7 @@ export class ReplayContainer implements ReplayContainerInterface {

if (!this.session) {
// This should not happen, something wrong has occurred
this._handleException(new Error('Unable to initialize and create session'));
this.handleException(new Error('Unable to initialize and create session'));
return;
}

Expand Down Expand Up @@ -389,7 +398,7 @@ export class ReplayContainer implements ReplayContainerInterface {
: {}),
});
} catch (err) {
this._handleException(err);
this.handleException(err);
}
}

Expand All @@ -408,7 +417,7 @@ export class ReplayContainer implements ReplayContainerInterface {

return true;
} catch (err) {
this._handleException(err);
this.handleException(err);
return false;
}
}
Expand Down Expand Up @@ -450,7 +459,7 @@ export class ReplayContainer implements ReplayContainerInterface {
// is started after, it will not have `previousSessionId`
clearSession(this);
} catch (err) {
this._handleException(err);
this.handleException(err);
}
}

Expand Down Expand Up @@ -777,15 +786,6 @@ export class ReplayContainer implements ReplayContainerInterface {
this.startRecording();
}

/** A wrapper to conditionally capture exceptions. */
private _handleException(error: unknown): void {
DEBUG_BUILD && logger.error('[Replay]', error);

if (DEBUG_BUILD && this._options._experiments && this._options._experiments.captureExceptions) {
captureException(error);
}
}

/**
* Loads (or refreshes) the current session.
*/
Expand Down Expand Up @@ -873,7 +873,7 @@ export class ReplayContainer implements ReplayContainerInterface {
this._hasInitializedCoreListeners = true;
}
} catch (err) {
this._handleException(err);
this.handleException(err);
}

this._performanceCleanupCallback = setupPerformanceObserver(this);
Expand All @@ -898,7 +898,7 @@ export class ReplayContainer implements ReplayContainerInterface {
this._performanceCleanupCallback();
}
} catch (err) {
this._handleException(err);
this.handleException(err);
}
}

Expand Down Expand Up @@ -1161,7 +1161,7 @@ export class ReplayContainer implements ReplayContainerInterface {
timestamp,
});
} catch (err) {
this._handleException(err);
this.handleException(err);

// This means we retried 3 times and all of them failed,
// or we ran into a problem we don't want to retry, like rate limiting.
Expand Down
1 change: 1 addition & 0 deletions packages/replay-internal/src/types/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ export interface ReplayContainer {
checkAndHandleExpiredSession(): boolean | void;
setInitialState(): void;
getCurrentRoute(): string | undefined;
handleException(err: unknown): void;
}

type RequestBody = null | Blob | BufferSource | FormData | URLSearchParams | string;
Expand Down
2 changes: 1 addition & 1 deletion packages/replay-internal/src/util/addEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ async function _addEvent(
return await replay.eventBuffer.addEvent(eventAfterPossibleCallback);
} catch (error) {
const reason = error && error instanceof EventBufferSizeExceededError ? 'addEventSizeExceeded' : 'addEvent';
replay.handleException(error);

DEBUG_BUILD && logger.error(error);
await replay.stop({ reason });

const client = getClient();
Expand Down
Loading