UNPKG

826 BPlain TextView Raw
1import { Platform } from 'expo-modules-core';
2
3import { getRecoveryPropsToSave } from './ErroRecoveryStore';
4import ExpoErrorRecovery from './ExpoErrorRecovery';
5
6if (Platform.OS !== 'web') {
7 const globalHandler = ErrorUtils.getGlobalHandler();
8 // ErrorUtils came from react-native
9 // https://github.com/facebook/react-native/blob/1151c096dab17e5d9a6ac05b61aacecd4305f3db/Libraries/vendor/core/ErrorUtils.js#L25
10 ErrorUtils.setGlobalHandler(async (error, isFatal) => {
11 if (ExpoErrorRecovery.saveRecoveryProps) {
12 await ExpoErrorRecovery.saveRecoveryProps(getRecoveryPropsToSave());
13 }
14 globalHandler(error, isFatal);
15 });
16} else if (Platform.OS === 'web' && Platform.isDOMAvailable) {
17 window.addEventListener('error', () => {
18 ExpoErrorRecovery.saveRecoveryProps(getRecoveryPropsToSave());
19 });
20}