Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ReactNative ErrorHandling Example - From Expo.io
const defaultHandler = (ErrorUtils.getGlobalHandler && ErrorUtils.getGlobalHandler()) || ErrorUtils._globalHandler;
const customErrorHandler = async (err, isFatal) => {
await AsyncStorage.setItem('lastError', JSON.stringify(err, Object.getOwnPropertyNames(err)));
return defaultHandler(err, isFatal);
};
ErrorUtils.setGlobalHandler(customErrorHandler);
//inside the App component:
async componentWillMount() {
const lastError = await AsyncStorage.getItem('lastError');
// dispatch error to logs
if (lastError) {
log({
sender: 'mobile-ops',
message: 'Fatal error !',
info: {
error: lastError
}
});
await AsyncStorage.removeItem('lastError');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.