Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isInternalException || !beforeSend) {
this._getBackend().sendEvent(finalEvent);
resolve(finalEvent);
return;
}
const beforeSendResult = beforeSend(prepared, hint);
if ((typeof beforeSendResult as any) === 'undefined') {
logger.error('`beforeSend` method has to return `null` or a valid event.');
} else if (isThenable(beforeSendResult)) {
this._handleAsyncBeforeSend(beforeSendResult as PromiseLike, resolve, reject);
} else {
finalEvent = beforeSendResult as Event | null;
if (finalEvent === null) {
logger.log('`beforeSend` returned `null`, will not send event.');
resolve(null);
return;
}
// From here on we are really async
this._getBackend().sendEvent(finalEvent);
resolve(finalEvent);
}
} catch (exception) {
this.captureException(exception, {
data: {
__sentry__: true,
},
originalException: exception as Error,
});
reject('`beforeSend` threw an error, will not send event.');
ErrorUtils.setGlobalHandler((error: any, isFatal?: boolean) => {
// We want to handle fatals, but only in production mode.
const shouldHandleFatal = isFatal && !global.__DEV__;
if (shouldHandleFatal) {
if (handlingFatal) {
logger.log(
"Encountered multiple fatals in a row. The latest:",
error
);
return;
}
handlingFatal = true;
}
getCurrentHub().withScope(scope => {
if (isFatal) {
scope.setLevel(Severity.Fatal);
}
getCurrentHub().captureException(error, {
originalException: error
});
});
public setupOnce(): void {
Error.stackTraceLimit = 50;
if (this._options.onerror) {
logger.log('Global Handler attached: onerror');
this._installGlobalOnErrorHandler();
}
if (this._options.onunhandledrejection) {
logger.log('Global Handler attached: onunhandledrejection');
this._installGlobalOnUnhandledRejectionHandler();
}
}
export function setupIntegration(integration: Integration): void {
if (installedIntegrations.indexOf(integration.name) !== -1) {
return;
}
integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
installedIntegrations.push(integration.name);
logger.log(`Integration installed: ${integration.name}`);
}
public setupOnce(): void {
Error.stackTraceLimit = 50;
if (this._options.onerror) {
logger.log('Global Handler attached: onerror');
this._installGlobalOnErrorHandler();
}
if (this._options.onunhandledrejection) {
logger.log('Global Handler attached: onunhandledrejection');
this._installGlobalOnUnhandledRejectionHandler();
}
}