Skip to content

Commit

Permalink
fix: Conditionally access constructor name. (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Sep 3, 2024
1 parent ca1fb88 commit 326295f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/telemetry/browser-telemetry/src/BrowserTelemetryImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,23 @@ export default class BrowserTelemetryImpl implements BrowserTelemetry {
}

captureError(exception: Error): void {
const data: ErrorData = {
type: exception.name || exception.constructor.name || 'generic',
message: exception.message,
stack: parse(exception, this.options.stack),
breadcrumbs: [...this.breadcrumbs],
sessionId: this.sessionId,
};
const validException = exception !== undefined && exception !== null;

const data: ErrorData = validException
? {
type: exception.name || exception.constructor?.name || 'generic',
message: exception.message,
stack: parse(exception, this.options.stack),
breadcrumbs: [...this.breadcrumbs],
sessionId: this.sessionId,
}
: {
type: 'generic',
message: 'null or undefined exception',
stack: { frames: [] },
breadcrumbs: [...this.breadcrumbs],
sessionId: this.sessionId,
};
this.capture(ERROR_KEY, data);
this.dispatchError(exception);
}
Expand Down

0 comments on commit 326295f

Please sign in to comment.