UNPKG

@sentry/lynx-react

Version:
1 lines 3.01 kB
{"version":3,"file":"globalHandlers.mjs","sources":["../../../src/integrations/globalHandlers.ts"],"sourcesContent":["import { captureException, Client, defineIntegration, getClient, type IntegrationFn } from \"@sentry/core\";\nimport { isLynxBackgroundThread } from \"../environment\";\n\nexport const INTEGRATION_NAME = 'LynxGlobalHandlers';\n\nconst createGlobalHandlersIntegration: IntegrationFn = ({\n background = true,\n}: {\n /**\n * Set this to true if you want to catch unhandled errors in the background thread.\n *\n * By default set to true.\n */\n background?: boolean;\n} = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup: (client: Client) => {\n if (background) {\n installBackgroundUnhandledErrorHandler(client);\n }\n },\n };\n};\n\nfunction installBackgroundUnhandledErrorHandler(client: Client) {\n if (isLynxBackgroundThread()) {\n const app = (lynx as any).getApp()\n const originalHandleError = app.handleError;\n app.handleError = function(error: Error, originError?: Error, errorLevel?: any) {\n if (getClient() !== client) {\n return;\n }\n \n captureException(originError, (scope) => {\n scope.setLevel('fatal')\n scope.addEventProcessor((event) => {\n if (event.exception?.values?.[0]) {\n event.exception.values[0].mechanism = {\n handled: false,\n type: 'onerror',\n }\n }\n return event;\n })\n return scope;\n })\n \n originalHandleError.call(app, error, originError, errorLevel)\n }\n }\n }\n\n/**\n * Use this integration to set up capturing unhandled errors.\n */\nexport const lynxGlobalHandlersIntegration = defineIntegration(createGlobalHandlersIntegration);\n"],"names":[],"mappings":";;;AAGO,MAAM,gBAAgB,GAAG;AAEhC,MAAM,+BAA+B,GAAkB,CAAC,EACtD,UAAU,GAAG,IAAI,GAAA,GAQf,EAAE,KAAI;IACR,OAAO;AACL,QAAA,IAAI,EAAE,gBAAgB;AACtB,QAAA,KAAK,EAAE,CAAC,MAAc,KAAI;AACxB,YAAA,IAAI,UAAU,EAAE;gBACd,sCAAsC,CAAC,MAAM,CAAC;AAC/C;SACF;KACF;AACH,CAAC;AAED,SAAS,sCAAsC,CAAC,MAAc,EAAA;IAC1D,IAAI,sBA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