Commit 7e266b4e authored by Robert Knight's avatar Robert Knight

Handle potentially undefined `event.extra` field

This issue was noticed after a TypeScript update.
parent e822ee15
...@@ -88,6 +88,9 @@ export function init(config) { ...@@ -88,6 +88,9 @@ export function init(config) {
try { try {
const originalErr = hint && hint.originalException; const originalErr = hint && hint.originalException;
if (originalErr instanceof Event) { if (originalErr instanceof Event) {
if (!event.extra) {
event.extra = {};
}
Object.assign(event.extra, { Object.assign(event.extra, {
type: originalErr.type, type: originalErr.type,
// @ts-ignore - `detail` is a property of certain event types. // @ts-ignore - `detail` is a property of certain event types.
......
...@@ -164,7 +164,7 @@ describe('sidebar/util/sentry', () => { ...@@ -164,7 +164,7 @@ describe('sidebar/util/sentry', () => {
it('extracts metadata from thrown `Event`s', () => { it('extracts metadata from thrown `Event`s', () => {
sentry.init({ dsn: 'test-dsn' }); sentry.init({ dsn: 'test-dsn' });
const beforeSend = getBeforeSendHook(); const beforeSend = getBeforeSendHook();
const event = { extra: {} }; const event = {};
beforeSend(event, { beforeSend(event, {
originalException: new CustomEvent('unexpectedevent', { originalException: new CustomEvent('unexpectedevent', {
...@@ -184,7 +184,7 @@ describe('sidebar/util/sentry', () => { ...@@ -184,7 +184,7 @@ describe('sidebar/util/sentry', () => {
it('ignores errors serializing non-Error exception values', () => { it('ignores errors serializing non-Error exception values', () => {
sentry.init({ dsn: 'test-dsn' }); sentry.init({ dsn: 'test-dsn' });
const beforeSend = getBeforeSendHook(); const beforeSend = getBeforeSendHook();
const event = { extra: {} }; const event = {};
const originalException = new CustomEvent('unexpectedevent'); const originalException = new CustomEvent('unexpectedevent');
Object.defineProperty(originalException, 'detail', { Object.defineProperty(originalException, 'detail', {
get: () => { get: () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment