Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup global error handling infrastructure #72

Open
acostalima opened this issue Jun 8, 2021 · 0 comments
Open

Setup global error handling infrastructure #72

acostalima opened this issue Jun 8, 2021 · 0 comments

Comments

@acostalima
Copy link
Contributor

acostalima commented Jun 8, 2021

See global.ErrorUtils.setGlobalHandler.

Example:

import { ExceptionsManager } from 'react-native';

global.ErrorUtils.setGlobalHandler((e, isFatal) => {
  if (__DEV__) {
    // In DEV, pass the error to the standard ExceptionsManager
    // This way you'll still get nice RSODs in DEV
    ExceptionsManager.handleException(e, isFatal);
  } else {
    // Not in DEV. Send the exception 'e' to your logger of choice
    sendErrorToCrashReporter(e.message);
  }
});

I'm not sure whether React Native exports ExceptionsManager, but it can be found at https://github.com/facebook/react-native/blob/7d1d4dc0645a5dfecc53d05b16338f9c08cc0d0f/ReactAndroid/src/main/java/com/facebook/react/modules/core/ExceptionsManagerModule.java

NOTE: setGlobalHandler does not catch native iOS and Android exceptions. Without further action if, e.g., sendErrorToCrashReporter throws, the app will crash with no useful feedback to the user. In order to handle native exceptions gracefully with enhanced user experience, consider something like react-native-exception-handler, maybe fork it or develop our own custom solution.

References:

@acostalima acostalima changed the title Setup global error handler Setup global error handling mechanisms Jun 8, 2021
@acostalima acostalima changed the title Setup global error handling mechanisms Setup global error handling infrastructure Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant