Skip to content

Commit 3857456

Browse files
committed
ref: simplify
1 parent abfd72f commit 3857456

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

packages/browser-integration-tests/suites/public-api/captureException/classInstance/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sentryTest('should capture an POJO', async ({ getLocalTestPath, page }) => {
1212
expect(eventData.exception?.values).toHaveLength(1);
1313
expect(eventData.exception?.values?.[0]).toMatchObject({
1414
type: 'Error',
15-
value: '`MyTestClass` captured as exception with keys: prop1, prop2',
15+
value: 'Object captured as exception with keys: prop1, prop2',
1616
mechanism: {
1717
type: 'generic',
1818
handled: true,

packages/browser-integration-tests/suites/public-api/captureException/event/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sentryTest('should capture an Event', async ({ getLocalTestPath, page }) => {
1212
expect(eventData.exception?.values).toHaveLength(1);
1313
expect(eventData.exception?.values?.[0]).toMatchObject({
1414
type: 'Event',
15-
value: 'Event `Event` (custom) captured as exception with keys: currentTarget, isTrusted, target, type',
15+
value: 'Event `Event` (type=custom) captured as exception',
1616
mechanism: {
1717
type: 'generic',
1818
handled: true,

packages/browser/src/eventbuilder.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,19 @@ function getNonErrorObjectExceptionValue(
290290
): string {
291291
const keys = extractExceptionKeysForMessage(exception);
292292
const captureType = isUnhandledRejection ? 'promise rejection' : 'exception';
293-
const className = getObjectClassName(exception);
294293

295294
// Some ErrorEvent instances do not have an `error` property, which is why they are not handled before
296295
// We still want to try to get a decent message for these cases
297296
if (isErrorEvent(exception)) {
298297
return `Event \`ErrorEvent\` captured as ${captureType} with message \`${exception.message}\``;
299298
}
300299

301-
const name = isEvent(exception)
302-
? `Event \`${className}\` (${exception.type})`
303-
: className && className !== 'Object'
304-
? `\`${className}\``
305-
: 'Object';
306-
307-
const label = `${name} captured as ${captureType}`;
300+
if (isEvent(exception)) {
301+
const className = getObjectClassName(exception);
302+
return `Event \`${className}\` (type=${exception.type}) captured as ${captureType}`;
303+
}
308304

309-
return `${label} with keys: ${keys}`;
305+
return `Object captured as ${captureType} with keys: ${keys}`;
310306
}
311307

312308
function getObjectClassName(obj: unknown): string | undefined | void {

packages/browser/test/integration/suites/onunhandledrejection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('window.onunhandledrejection', function () {
7777
// non-error rejections don't provide stacktraces so we can skip that assertion
7878
assert.equal(
7979
summary.events[0].exception.values[0].value,
80-
'Event `Event` (unhandledrejection) captured as promise rejection with keys: currentTarget, isTrusted, target, type'
80+
'Event `Event` (type=unhandledrejection) captured as promise rejection'
8181
);
8282
assert.equal(summary.events[0].exception.values[0].type, 'Event');
8383
assert.equal(summary.events[0].exception.values[0].mechanism.handled, false);

packages/browser/test/unit/eventbuilder.test.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,9 @@ describe('eventFromPlainObject', () => {
7070
it.each([
7171
['empty object', {}, 'Object captured as exception with keys: [object has no keys]'],
7272
['pojo', { prop1: 'hello', prop2: 2 }, 'Object captured as exception with keys: prop1, prop2'],
73-
['Custom Class', new MyTestClass(), '`MyTestClass` captured as exception with keys: prop1, prop2'],
74-
[
75-
'Event',
76-
new Event('custom'),
77-
'Event `Event` (custom) captured as exception with keys: currentTarget, isTrusted, target, type',
78-
],
79-
[
80-
'MouseEvent',
81-
new MouseEvent('click'),
82-
'Event `MouseEvent` (click) captured as exception with keys: currentTarget, isTrusted, target, type',
83-
],
73+
['Custom Class', new MyTestClass(), 'Object captured as exception with keys: prop1, prop2'],
74+
['Event', new Event('custom'), 'Event `Event` (type=custom) captured as exception'],
75+
['MouseEvent', new MouseEvent('click'), 'Event `MouseEvent` (type=click) captured as exception'],
8476
] as [string, Record<string, unknown>, string][])(
8577
'has correct exception value for %s',
8678
(_name, exception, expected) => {

0 commit comments

Comments
 (0)