How do we use ErrorRecovery?


Trying to get the error recovery working in prod. What goes into “props” here? Also, where do I declare this (presumably on app load?). Additionally, how do I recover the actual errors on the subsequent app restart (.e.g exp.errorRecovery)? Could we get an example of this in code?

1 Like

Would love to see some info on this as well. The docs are pretty sparse.

I am working on this as we speak but here’s what I got so far:

1.According to the documentation, when a fatal error occurs( or global error, whatever you want to call it), expo will allow you to set arbitrary props on as the initial props for you app (via ErrorRecovery.setRecoveryProps). This doesn’t help a bit in telling us how to get the actual error.
2.According to this : what we need to do is replace the default global error handler (the one set by expo that does the app reload in prod) with a custom one that will:
a) log the error
b) ErrorRecovery.setRecoveryProps(the error)
c) maybe do some other stuff
d) call the original error handler (to get the crash behaviour Expo is talking about in the docs)

Hope this helps, I’ll update if this works out ok.

Update: I ended up doing this:
in my App.js
outside the App component:

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);

inside the App component:
async componentWillMount() {
const lastError = await AsyncStorage.getItem(‘lastError’);
// dispatch error to logs
if (lastError) {
sender: ‘mobile-ops’,
message: ‘Fatal error !’,
info: {
error: lastError
await AsyncStorage.removeItem(‘lastError’);

Works like a charm, couldn’t get ErrorRecovery.setRecoveryProps to work reliably so I went the localstorage route.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.