diff --git a/packages/core/src/integrations/inboundfilters.ts b/packages/core/src/integrations/inboundfilters.ts index abe7948f2547..da24883f2285 100644 --- a/packages/core/src/integrations/inboundfilters.ts +++ b/packages/core/src/integrations/inboundfilters.ts @@ -169,20 +169,35 @@ function _isAllowedUrl(event: Event, allowUrls?: Array): boolea } function _getPossibleEventMessages(event: Event): string[] { + const possibleMessages: string[] = []; + if (event.message) { - return [event.message]; + possibleMessages.push(event.message); } - if (event.exception) { - const { values } = event.exception; - try { - 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)}`); - return []; + + let lastException; + try { + // @ts-ignore Try catching to save bundle size + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + lastException = event.exception.values[event.exception.values.length - 1]; + } catch (e) { + // try catching to save bundle size checking existence of variables + } + + if (lastException) { + if (lastException.value) { + possibleMessages.push(lastException.value); + if (lastException.type) { + possibleMessages.push(`${lastException.type}: ${lastException.value}`); + } } } - return []; + + if (__DEBUG_BUILD__ && possibleMessages.length === 0) { + logger.error(`Could not extract message for event ${getEventDescription(event)}`); + } + + return possibleMessages; } function _isSentryError(event: Event): boolean { diff --git a/packages/core/test/lib/integrations/inboundfilters.test.ts b/packages/core/test/lib/integrations/inboundfilters.test.ts index 88ab23f65909..9888a59eedff 100644 --- a/packages/core/test/lib/integrations/inboundfilters.test.ts +++ b/packages/core/test/lib/integrations/inboundfilters.test.ts @@ -125,6 +125,18 @@ const EXCEPTION_EVENT: Event = { }, }; +const EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE: Event = { + message: 'ChunkError', + exception: { + values: [ + { + type: 'SyntaxError', + value: 'unidentified ? at line 1337', + }, + ], + }, +}; + const EXCEPTION_EVENT_WITH_FRAMES: Event = { exception: { values: [ @@ -336,6 +348,17 @@ describe('InboundFilters', () => { }); expect(eventProcessor(EXCEPTION_EVENT, {})).toBe(null); }); + + it('should consider both `event.message` and the last exceptions `type` and `value`', () => { + const messageEventProcessor = createInboundFiltersEventProcessor({ + ignoreErrors: [/^ChunkError/], + }); + const valueEventProcessor = createInboundFiltersEventProcessor({ + ignoreErrors: [/^SyntaxError/], + }); + expect(messageEventProcessor(EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE, {})).toBe(null); + expect(valueEventProcessor(EXCEPTION_EVENT_WITH_MESSAGE_AND_VALUE, {})).toBe(null); + }); }); });