Created
July 27, 2020 14:31
-
-
Save ospfranco/f11b8e01615279ba7a006c5dcf72fccb to your computer and use it in GitHub Desktop.
Attach Javascript stack to Crashlytics
This file contains 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
// If you are using crashlytics and you cannot update to the latest versions of react-native-firebase (or need sourcemaps which is doesn't support) adding middleware to the error handling can at least provide you with an error stack | |
//Define an error handler to upload thet stack to crashlytics | |
const defaultHandler = global.ErrorUtils.getGlobalHandler() | |
const crashlytics = firebase.crashlytics() | |
global.ErrorUtils.setGlobalHandler((...args) => { | |
const error = args[0] || 'Unknown' | |
//console.log('Crashlytics error sent', error); | |
if (error instanceof Error) { | |
crashlytics.setStringValue('stack', `${error.stack}`) | |
crashlytics.setStringValue('message', `${error.message}`) | |
crashlytics.recordError(0, `RN Fatal: ${error.message}`) | |
} else { | |
// Have never gotten this log so far. Might not be necessary. | |
crashlytics.recordError(0, `RN Fatal: ${error}`) | |
} | |
crashlytics.log(error.message); | |
defaultHandler.apply(this, args); | |
//force the native crash | |
crashlytics.crash(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment