Skip to content

Commit eae7ba9

Browse files
committed
feat: Skip beforeSend when throwing internal exception
1 parent f37ed1a commit eae7ba9

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

packages/core/src/baseclient.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,22 +363,41 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
363363
};
364364
}
365365

366-
const finalEvent = beforeSend ? await beforeSend(prepared, hint) : prepared;
367-
if (finalEvent === null) {
366+
try {
367+
const isInternalException = hint && hint.data && hint.data.__sentry__ === true;
368+
let finalEvent: SentryEvent | null = prepared;
369+
370+
if (!isInternalException && beforeSend) {
371+
finalEvent = await beforeSend(prepared, hint);
372+
}
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;
389+
} catch (exception) {
390+
this.captureException(exception, {
391+
data: {
392+
__sentry__: true,
393+
},
394+
originalException: exception,
395+
});
396+
368397
return {
369-
status: Status.Skipped,
398+
status: Status.Invalid,
370399
};
371400
}
372-
373-
const response = await send(finalEvent);
374-
response.event = finalEvent;
375-
376-
if (response.status === Status.RateLimit) {
377-
// TODO: Handle rate limits and maintain a queue. For now, we require SDK
378-
// implementors to override this method and handle it themselves.
379-
}
380-
381-
return response;
382401
}
383402

384403
/**

0 commit comments

Comments
 (0)