Skip to content

Instantly share code, notes, and snippets.

@SudoPlz

SudoPlz/CrashReporter.js

Last active Mar 19, 2018
Embed
What would you like to do?
import { Client, Configuration } from 'bugsnag-react-native';
module.exports = { // cached singleton instance
instance: null,
create(key, store, codeBundleId) {
if (this.instance === null) {
if (key == null) {
throw new Error(`Crash Reporter should be created with a
key as the first param. i.e .create(key, reduxStore)`);
}
const bugsnagConfig = new Configuration(key);
bugsnagConfig.shouldNotify = () => !__DEV__;
// code bundle id
if (codeBundleId) {
bugsnagConfig.codeBundleId = codeBundleId;
}
bugsnagConfig.notifyReleaseStages = ['production', 'staging', 'testflight'];
bugsnagConfig.registerBeforeSendCallback((report) => {
const state = JSON.parse(JSON.stringify(store.getState()));
const metadata = report.metadata || {};
// add our calendar state as metadata
metadata.calendar = state.calendar;
if (metadata.app == null) {
metadata.app = {};
}
// if the codebundleid is null, add it to the metadata
if (metadata.app.codeBundleId == null) {
metadata.app.codeBundleId = codeBundleId;
}
report.metadata = metadata;
});
this.instance = new Client(bugsnagConfig);
}
return this.instance;
},
};
CrashReporter.create(CONFIG.BUGSNAG_KEY, store, curAppVersion);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment