Created
July 15, 2016 10:07
-
-
Save mohanrohith/2ba9655e29110ece390024adc4930fb1 to your computer and use it in GitHub Desktop.
Error handler for React Native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import StackTrace from 'stacktrace-js' | |
const Fabric = require('react-native-fabric') | |
const { Crashlytics } = Fabric | |
// call this to start capturing any no-handled errors | |
exports.init = function () { | |
const originalHandler = global.ErrorUtils.getGlobalHandler() | |
function errorHandler (e) { | |
exports.issue(e) | |
if (originalHandler) { | |
originalHandler(e) | |
} | |
} | |
global.ErrorUtils.setGlobalHandler(errorHandler) | |
} | |
exports.issue = function (e) { | |
StackTrace.fromError(e, {offline: true}).then((stack) => { | |
stack = stack.map(row => { | |
let {source, lineNumber} = row | |
return {fileName: e.message, lineNumber: lineNumber || 0, functionName: source} | |
}) | |
Crashlytics.recordCustomExceptionName(e.message, e.message, stack) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment