Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jun 22, 2023
1 parent 0e6cf14 commit 9e08fb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/browser/src/eventbuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ function getNonErrorObjectExceptionValue(
): string {
const keys = extractExceptionKeysForMessage(exception);
const captureType = isUnhandledRejection ? 'promise rejection' : 'exception';
const prototype: Prototype | null = Object.getPrototypeOf(exception);
const className = prototype ? prototype.constructor.name : undefined;
const className = getObjectClassName(exception);

// Some ErrorEvent instances do not have an `error` property, which is why they are not handled before
// We still want to try to get a decent message for these cases
Expand All @@ -309,3 +308,12 @@ function getNonErrorObjectExceptionValue(

return `${label} with keys: ${keys}`;
}

function getObjectClassName(obj: unknown): string | undefined | void {
try {
const prototype: Prototype | null = Object.getPrototypeOf(obj);
return prototype ? prototype.constructor.name : undefined;
} catch (e) {
// ignore errors here
}
}
2 changes: 1 addition & 1 deletion packages/utils/src/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function isBuiltin(wat: unknown, className: string): boolean {
* @param wat A value to be checked.
* @returns A boolean representing the result.
*/
export function isErrorEvent(wat: unknown): wat is ErrorEvent {
export function isErrorEvent(wat: unknown): boolean {
return isBuiltin(wat, 'ErrorEvent');
}

Expand Down

0 comments on commit 9e08fb6

Please sign in to comment.