Skip to content

Instantly share code, notes, and snippets.

@mohanrohith
Created July 15, 2016 10:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohanrohith/2ba9655e29110ece390024adc4930fb1 to your computer and use it in GitHub Desktop.
Save mohanrohith/2ba9655e29110ece390024adc4930fb1 to your computer and use it in GitHub Desktop.
Error handler for React Native
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