diff --git a/packages/core/src/integrations/inboundfilters.ts b/packages/core/src/integrations/inboundfilters.ts index 7c2319596ebd..998c7ab8203d 100644 --- a/packages/core/src/integrations/inboundfilters.ts +++ b/packages/core/src/integrations/inboundfilters.ts @@ -152,8 +152,9 @@ function _getPossibleEventMessages(event: Event): string[] { return [event.message]; } if (event.exception) { + const { values } = event.exception; try { - const { type = '', value = '' } = (event.exception.values && event.exception.values[0]) || {}; + const { type = '', value = '' } = (values && values[values.length - 1]) || {}; return [`${value}`, `${type}: ${value}`]; } catch (oO) { __DEBUG_BUILD__ && logger.error(`Cannot extract message for event ${getEventDescription(event)}`); diff --git a/packages/core/test/lib/integrations/inboundfilters.test.ts b/packages/core/test/lib/integrations/inboundfilters.test.ts index 51b5e9106d64..a528d765bfeb 100644 --- a/packages/core/test/lib/integrations/inboundfilters.test.ts +++ b/packages/core/test/lib/integrations/inboundfilters.test.ts @@ -143,6 +143,21 @@ const EXCEPTION_EVENT_WITH_FRAMES: Event = { }, }; +const EXCEPTION_EVENT_WITH_LINKED_ERRORS: Event = { + exception: { + values: [ + { + type: 'ReferenceError', + value: '`tooManyTreats` is not defined', + }, + { + type: 'TypeError', + value: 'incorrect type given for parameter `chewToy`: Shoe', + }, + ], + }, +}; + const SENTRY_EVENT: Event = { exception: { values: [ @@ -271,6 +286,20 @@ describe('InboundFilters', () => { expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null); }); + it('filters on last exception when multiple present', () => { + const eventProcessor = createInboundFiltersEventProcessor({ + ignoreErrors: ['incorrect type given for parameter `chewToy`'], + }); + expect(eventProcessor(EXCEPTION_EVENT_WITH_LINKED_ERRORS, {})).toBe(null); + }); + + it("doesn't filter on `cause` exception when multiple present", () => { + const eventProcessor = createInboundFiltersEventProcessor({ + ignoreErrors: ['`tooManyTreats` is not defined'], + }); + expect(eventProcessor(EXCEPTION_EVENT_WITH_LINKED_ERRORS, {})).toBe(EXCEPTION_EVENT_WITH_LINKED_ERRORS); + }); + describe('on exception', () => { it('uses exception data when message is unavailable', () => { const eventProcessor = createInboundFiltersEventProcessor({