diff --git a/packages/browser-integration-tests/suites/public-api/captureException/classInstance/test.ts b/packages/browser-integration-tests/suites/public-api/captureException/classInstance/test.ts index 6aae7660d394..3a8865ec3672 100644 --- a/packages/browser-integration-tests/suites/public-api/captureException/classInstance/test.ts +++ b/packages/browser-integration-tests/suites/public-api/captureException/classInstance/test.ts @@ -12,7 +12,7 @@ sentryTest('should capture an POJO', async ({ getLocalTestPath, page }) => { expect(eventData.exception?.values).toHaveLength(1); expect(eventData.exception?.values?.[0]).toMatchObject({ type: 'Error', - value: '`MyTestClass` captured as exception with keys: prop1, prop2', + value: 'Object captured as exception with keys: prop1, prop2', mechanism: { type: 'generic', handled: true, diff --git a/packages/browser-integration-tests/suites/public-api/captureException/event/test.ts b/packages/browser-integration-tests/suites/public-api/captureException/event/test.ts index 7981f0608cb0..65c46a776731 100644 --- a/packages/browser-integration-tests/suites/public-api/captureException/event/test.ts +++ b/packages/browser-integration-tests/suites/public-api/captureException/event/test.ts @@ -12,7 +12,7 @@ sentryTest('should capture an Event', async ({ getLocalTestPath, page }) => { expect(eventData.exception?.values).toHaveLength(1); expect(eventData.exception?.values?.[0]).toMatchObject({ type: 'Event', - value: 'Event `Event` (custom) captured as exception with keys: currentTarget, isTrusted, target, type', + value: 'Event `Event` (type=custom) captured as exception', mechanism: { type: 'generic', handled: true, diff --git a/packages/browser/src/eventbuilder.ts b/packages/browser/src/eventbuilder.ts index 8706ee4403f7..6acc1080c56f 100644 --- a/packages/browser/src/eventbuilder.ts +++ b/packages/browser/src/eventbuilder.ts @@ -290,7 +290,6 @@ function getNonErrorObjectExceptionValue( ): string { const keys = extractExceptionKeysForMessage(exception); const captureType = isUnhandledRejection ? 'promise rejection' : 'exception'; - 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 @@ -298,15 +297,12 @@ function getNonErrorObjectExceptionValue( return `Event \`ErrorEvent\` captured as ${captureType} with message \`${exception.message}\``; } - const name = isEvent(exception) - ? `Event \`${className}\` (${exception.type})` - : className && className !== 'Object' - ? `\`${className}\`` - : 'Object'; - - const label = `${name} captured as ${captureType}`; + if (isEvent(exception)) { + const className = getObjectClassName(exception); + return `Event \`${className}\` (type=${exception.type}) captured as ${captureType}`; + } - return `${label} with keys: ${keys}`; + return `Object captured as ${captureType} with keys: ${keys}`; } function getObjectClassName(obj: unknown): string | undefined | void { diff --git a/packages/browser/test/integration/suites/onunhandledrejection.js b/packages/browser/test/integration/suites/onunhandledrejection.js index cb1aec9dae41..f9095d7c7333 100644 --- a/packages/browser/test/integration/suites/onunhandledrejection.js +++ b/packages/browser/test/integration/suites/onunhandledrejection.js @@ -77,7 +77,7 @@ describe('window.onunhandledrejection', function () { // non-error rejections don't provide stacktraces so we can skip that assertion assert.equal( summary.events[0].exception.values[0].value, - 'Event `Event` (unhandledrejection) captured as promise rejection with keys: currentTarget, isTrusted, target, type' + 'Event `Event` (type=unhandledrejection) captured as promise rejection' ); assert.equal(summary.events[0].exception.values[0].type, 'Event'); assert.equal(summary.events[0].exception.values[0].mechanism.handled, false); diff --git a/packages/browser/test/unit/eventbuilder.test.ts b/packages/browser/test/unit/eventbuilder.test.ts index 1a8478036534..d7a2ab712959 100644 --- a/packages/browser/test/unit/eventbuilder.test.ts +++ b/packages/browser/test/unit/eventbuilder.test.ts @@ -70,17 +70,9 @@ describe('eventFromPlainObject', () => { it.each([ ['empty object', {}, 'Object captured as exception with keys: [object has no keys]'], ['pojo', { prop1: 'hello', prop2: 2 }, 'Object captured as exception with keys: prop1, prop2'], - ['Custom Class', new MyTestClass(), '`MyTestClass` captured as exception with keys: prop1, prop2'], - [ - 'Event', - new Event('custom'), - 'Event `Event` (custom) captured as exception with keys: currentTarget, isTrusted, target, type', - ], - [ - 'MouseEvent', - new MouseEvent('click'), - 'Event `MouseEvent` (click) captured as exception with keys: currentTarget, isTrusted, target, type', - ], + ['Custom Class', new MyTestClass(), 'Object captured as exception with keys: prop1, prop2'], + ['Event', new Event('custom'), 'Event `Event` (type=custom) captured as exception'], + ['MouseEvent', new MouseEvent('click'), 'Event `MouseEvent` (type=click) captured as exception'], ] as [string, Record, string][])( 'has correct exception value for %s', (_name, exception, expected) => {