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