UNPKG

@ammarahmed/notifee-react-native

Version:

Notifee - a feature rich notifications library for React Native.

61 lines 2.22 kB
"use strict"; /* * Copyright (c) 2016-present Invertase Limited */ Object.defineProperty(exports, "__esModule", { value: true }); class NotifeeNativeError extends Error { code; nativeErrorCode; nativeErrorMessage; jsStack; // TODO native error type // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types constructor(nativeError, jsStack = '') { super(); const { userInfo } = nativeError; this.code = `${userInfo.code || 'unknown'}`; Object.defineProperty(this, 'code', { enumerable: false, value: `${userInfo.code || 'unknown'}`, }); this.jsStack = jsStack; Object.defineProperty(this, 'jsStack', { enumerable: false, value: jsStack, }); Object.defineProperty(this, 'message', { enumerable: false, value: `[${this.code}] ${userInfo.message || nativeError.message}`, }); Object.defineProperty(this, 'userInfo', { enumerable: false, value: userInfo, }); this.nativeErrorCode = userInfo.nativeErrorCode || null; Object.defineProperty(this, 'nativeErrorCode', { enumerable: false, value: userInfo.nativeErrorCode || null, }); this.nativeErrorMessage = userInfo.nativeErrorMessage || null; Object.defineProperty(this, 'nativeErrorMessage', { enumerable: false, value: userInfo.nativeErrorMessage || null, }); this.stack = this.getStackWithMessage(`NativeError: ${this.message}`); } // todo errorEvent type // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types static fromEvent(errorEvent, stack) { return new NotifeeNativeError({ userInfo: errorEvent }, stack || new Error().stack); } /** * Build a stack trace that includes JS stack prior to calling the native method. * * @returns {string} */ getStackWithMessage(message) { return [message, ...this.jsStack.split('\n').slice(2, 13)].join('\n'); } } exports.default = NotifeeNativeError; //# sourceMappingURL=NotifeeNativeError.js.map