Skip to content

Commit d7839ce

Browse files
committed
add code to event message if name undefined
1 parent 75d3225 commit d7839ce

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/browser/src/eventbuilder.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,22 @@ export function eventFromUnknownInput(
7676
event = eventFromStacktrace(computeStackTrace(exception as Error));
7777
return event;
7878
}
79-
if (isDOMError(exception as DOMError) || isDOMException(exception as DOMException)) {
79+
if (isDOMError(exception) || isDOMException(exception)) {
8080
// If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
81-
// then we just extract the name and message, as they don't provide anything else
81+
// then we just extract the name, code, and message, as they don't provide anything else
8282
// https://developer.mozilla.org/en-US/docs/Web/API/DOMError
8383
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
84-
const domException = exception as DOMException;
85-
const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
86-
const message = domException.message ? `${name}: ${domException.message}` : name;
8784

88-
event = eventFromString(message, syntheticException, options);
89-
addExceptionTypeValue(event, message);
85+
// eslint-disable-next-line prefer-const
86+
let { name, code, message } = exception as DOMException;
87+
if (!name) {
88+
name = isDOMError(exception) ? 'DOMError' : 'DOMException';
89+
name = code ? `${name} (${code})` : name;
90+
}
91+
const eventMessage = message ? `${name}: ${message}` : name;
92+
93+
event = eventFromString(eventMessage, syntheticException, options);
94+
addExceptionTypeValue(event, eventMessage);
9095
return event;
9196
}
9297
if (isError(exception as Error)) {

0 commit comments

Comments
 (0)