How to use the react-native-exception-handler.getJSExceptionHandler function in react-native-exception-handler

To help you get started, we’ve selected a few react-native-exception-handler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wuyanwuyan / react_native_app_start_kit / index.js View on Github external
import { AppRegistry } from 'react-native';
import App from './src/index';

import {setJSExceptionHandler, getJSExceptionHandler,setNativeExceptionHandler} from 'react-native-exception-handler';

const customErrorHandler = (error, isFatal) => {
    // Logic for reporting to devs
    // Example : Log issues to github issues using github apis.

    console.log(error, isFatal); // example

};

const previousErrorHandler = getJSExceptionHandler(); // by default u will get the red screen error handler here

const errorHandler = (e, isFatal) => {
    customErrorHandler(e, isFatal);
    previousErrorHandler(e, isFatal);
};

// We will still see the error screen, but our customErrorHandler() function will be called
setJSExceptionHandler(errorHandler);


setNativeExceptionHandler((exceptionString) => {
    // This is your custom global error handler
    // You do stuff likehit google analytics to track crashes.
    // or hit a custom api to inform the dev team.
    //NOTE: alert or showing any UI change via JS
    //WILL NOT WORK in case of NATIVE ERRORS.

react-native-exception-handler

A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis