UNPKG

@sentry/lynx-react

Version:
48 lines (45 loc) 1.79 kB
import { defineIntegration, getClient, captureException } from '@sentry/core'; import { isLynxBackgroundThread } from '../environment.mjs'; const INTEGRATION_NAME = 'LynxGlobalHandlers'; const createGlobalHandlersIntegration = ({ background = true, } = {}) => { return { name: INTEGRATION_NAME, setup: (client) => { if (background) { installBackgroundUnhandledErrorHandler(client); } }, }; }; function installBackgroundUnhandledErrorHandler(client) { if (isLynxBackgroundThread()) { const app = lynx.getApp(); const originalHandleError = app.handleError; app.handleError = function (error, originError, errorLevel) { if (getClient() !== client) { return; } captureException(originError, (scope) => { scope.setLevel('fatal'); scope.addEventProcessor((event) => { var _a, _b; if ((_b = (_a = event.exception) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b[0]) { event.exception.values[0].mechanism = { handled: false, type: 'onerror', }; } return event; }); return scope; }); originalHandleError.call(app, error, originError, errorLevel); }; } } /** * Use this integration to set up capturing unhandled errors. */ const lynxGlobalHandlersIntegration = defineIntegration(createGlobalHandlersIntegration); export { INTEGRATION_NAME, lynxGlobalHandlersIntegration }; //# sourceMappingURL=globalHandlers.mjs.map