Skip to content

Commit 63591ef

Browse files
committed
Add reasons
1 parent eae7ba9 commit 63591ef

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

packages/core/src/baseclient.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Status,
1111
} from '@sentry/types';
1212
import { getGlobalObject, uuid4 } from '@sentry/utils/misc';
13+
import { forget } from '@sentry/utils/async';
1314
import { truncate } from '@sentry/utils/string';
1415
import { BackendClass } from './basebackend';
1516
import { Dsn } from './dsn';
@@ -363,41 +364,45 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
363364
};
364365
}
365366

366-
try {
367-
const isInternalException = hint && hint.data && hint.data.__sentry__ === true;
368-
let finalEvent: SentryEvent | null = prepared;
367+
let finalEvent: SentryEvent | null = prepared;
369368

369+
try {
370+
const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;
370371
if (!isInternalException && beforeSend) {
371372
finalEvent = await beforeSend(prepared, hint);
372373
}
373-
374-
if (finalEvent === null) {
375-
return {
376-
status: Status.Skipped,
377-
};
378-
}
379-
380-
const response = await send(finalEvent);
381-
response.event = finalEvent;
382-
383-
if (response.status === Status.RateLimit) {
384-
// TODO: Handle rate limits and maintain a queue. For now, we require SDK
385-
// implementors to override this method and handle it themselves.
386-
}
387-
388-
return response;
389374
} catch (exception) {
390-
this.captureException(exception, {
391-
data: {
392-
__sentry__: true,
393-
},
394-
originalException: exception,
395-
});
375+
forget(
376+
this.captureException(exception, {
377+
data: {
378+
__sentry__: true,
379+
},
380+
originalException: exception as Error,
381+
}),
382+
);
396383

397384
return {
385+
reason: 'Event processing in beforeSend method threw an exception',
398386
status: Status.Invalid,
399387
};
400388
}
389+
390+
if (finalEvent === null) {
391+
return {
392+
reason: 'Event dropped due to being discarded by beforeSend method',
393+
status: Status.Skipped,
394+
};
395+
}
396+
397+
const response = await send(finalEvent);
398+
response.event = finalEvent;
399+
400+
if (response.status === Status.RateLimit) {
401+
// TODO: Handle rate limits and maintain a queue. For now, we require SDK
402+
// implementors to override this method and handle it themselves.
403+
}
404+
405+
return response;
401406
}
402407

403408
/**

0 commit comments

Comments
 (0)