Skip to content

Drop-in support for capturing errors from React Native's global error handler.

License

Notifications You must be signed in to change notification settings

collegepulse/react-native-stacktrace

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-stacktrace

Drop-in support for capturing errors from React Native's global error handler. Pass in a custom configuration function to log errors wherever you want.

After you process the error and your Promise is fulfilled or rejected, the original error will be thrown, retaining the original system functionality.

Usage

To use, add this code to your index.ios.js and index.android.js (or some library included by both).

Call the init function. It takes a single function which returns a Promise.

import stacktrace from 'react-native-stacktrace';

stacktrace.init(function onError(err, isFatal) {
  return new Promise((resolve, reject) => {
    // log to your own logging service
    return doAsyncThingWithError(err, isFatal)
      .then(resolve)
      .catch(reject);
  });
});

Catching Uncaught Promises

React Native's default promise implementation, then/promise, can be subtituted with the CoreJS implementation. This permits the use of the window.onunhandledrejection handler.

// index.ios.js
import 'core-js';

window.onunhandledrejection = function(promise, reason) {
  console.log('window.onunhandledrejection is', promise, reason);
};

About

Drop-in support for capturing errors from React Native's global error handler.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%