1"use strict"; 2var __importDefault = (this && this.__importDefault) || function (mod) { 3 return (mod && mod.__esModule) ? mod : { "default": mod }; 4}; 5Object.defineProperty(exports, "__esModule", { value: true }); 6exports.useRejectionHandler = void 0; 7const react_1 = __importDefault(require("react")); 8const ExceptionsManager_1 = __importDefault(require("./modules/ExceptionsManager")); 9function useStackTraceLimit(limit) { 10 const current = react_1.default.useRef(0); 11 react_1.default.useEffect(() => { 12 try { 13 // @ts-expect-error: StackTraceLimit is not defined in the Error type 14 const currentLimit = Error.stackTraceLimit; 15 // @ts-expect-error: StackTraceLimit is not defined in the Error type 16 Error.stackTraceLimit = limit; 17 current.current = currentLimit; 18 } 19 catch { } 20 return () => { 21 try { 22 // @ts-expect-error: StackTraceLimit is not defined in the Error type 23 Error.stackTraceLimit = current.current; 24 } 25 catch { } 26 }; 27 }, [limit]); 28} 29function useRejectionHandler() { 30 const hasError = react_1.default.useRef(false); 31 useStackTraceLimit(35); 32 react_1.default.useEffect(() => { 33 function onUnhandledError(ev) { 34 hasError.current = true; 35 const error = ev?.error; 36 if (!error || !(error instanceof Error) || typeof error.stack !== 'string') { 37 return; 38 } 39 ExceptionsManager_1.default.handleException(error); 40 } 41 function onUnhandledRejection(ev) { 42 hasError.current = true; 43 const reason = ev?.reason; 44 if (!reason || !(reason instanceof Error) || typeof reason.stack !== 'string') { 45 return; 46 } 47 ExceptionsManager_1.default.handleException(reason); 48 } 49 window.addEventListener('unhandledrejection', onUnhandledRejection); 50 window.addEventListener('error', onUnhandledError); 51 return () => { 52 window.removeEventListener('error', onUnhandledError); 53 window.removeEventListener('unhandledrejection', onUnhandledRejection); 54 }; 55 }, []); 56 return hasError; 57} 58exports.useRejectionHandler = useRejectionHandler; 59//# sourceMappingURL=useRejectionHandler.js.map