UNPKG

@embrace-io/react-native

Version:
37 lines (36 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.trackUnhandledRejection = exports.enableUnhandledRejectionTracking = void 0; const EmbraceManagerModule_1 = require("../EmbraceManagerModule"); const UNHANDLED_PROMISE_REJECTION_PREFIX = "Unhandled promise rejection"; const trackUnhandledRejection = (_, error) => { let message = `${UNHANDLED_PROMISE_REJECTION_PREFIX}: ${error}`; let stackTrace = ""; if (error && error.message) { message = `${UNHANDLED_PROMISE_REJECTION_PREFIX}: ${error.message}`; stackTrace = error.stack || ""; } return EmbraceManagerModule_1.EmbraceManagerModule.logMessageWithSeverityAndProperties(message, "error", {}, stackTrace, !!stackTrace); }; exports.trackUnhandledRejection = trackUnhandledRejection; const REJECTION_TRACKING_CONFIG = { allRejections: true, onUnhandled: trackUnhandledRejection, onHandled: () => { }, }; const enableUnhandledRejectionTracking = () => { var _a, _b; // @ts-expect-error to allow for checking if HermesInternal exists on `global` since it isn't part of its type const hermesInternal = global === null || global === void 0 ? void 0 : global.HermesInternal; // Do the same checking as react-native to make sure we add tracking to the right Promise implementation // https://github.com/facebook/react-native/blob/v0.77.0/packages/react-native/Libraries/Core/polyfillPromise.js#L25 if ((_a = hermesInternal === null || hermesInternal === void 0 ? void 0 : hermesInternal.hasPromise) === null || _a === void 0 ? void 0 : _a.call(hermesInternal)) { (_b = hermesInternal === null || hermesInternal === void 0 ? void 0 : hermesInternal.enablePromiseRejectionTracker) === null || _b === void 0 ? void 0 : _b.call(hermesInternal, REJECTION_TRACKING_CONFIG); } else { // [Unhandled Rejections](https://github.com/then/promise/blob/master/Readme.md#unhandled-rejections) // [promise/setimmediate/rejection-tracking](https://github.com/then/promise/blob/master/src/rejection-tracking.js) require("promise/setimmediate/rejection-tracking").enable(REJECTION_TRACKING_CONFIG); } }; exports.enableUnhandledRejectionTracking = enableUnhandledRejectionTracking;