import 'bugsnag-js';
import isError from 'lodash/isError';
import isString from 'lodash/isString';
import config from '../config';
import {getCurrentProject} from '../selectors';

const Bugsnag = window.Bugsnag.noConflict();
Bugsnag.apiKey = config.bugsnagApiKey;
Bugsnag.releaseStage = config.nodeEnv;
Bugsnag.appVersion = config.gitRevision;

export function includeStoreInBugReports(store) {
  Bugsnag.beforeNotify = (payload) => {
    const state = store.getState();
    if (state.get('user')) {
      payload.user = state.get('user').toJS();
    } else {
      payload.user = {id: 'anonymous'};
    }

    const currentProject = getCurrentProject(state);
    if (currentProject) {
      payload.metaData.currentProject = currentProject;
    }
  };
}

window.addEventListener('unhandledrejection', ({reason}) => {
  if (isError(reason)) {
    Bugsnag.notifyException(reason);
  } else if (isString(reason)) {
    Bugsnag.notify('UnhandledRejection', reason);
  } else {
    Bugsnag.notify(
      'UnhandledRejection',
      JSON.stringify(reason) || 'No reason given',
    );
  }
});

export default Bugsnag;

@@ -18,86 +18,8 @@
 s';%0A
-import isError from 'lodash/isError';%0Aimport isString from 'lodash/isString';%0A
 impo
@@ -675,185 +675,28 @@
 %0A%7D%0A%0A
-window.addEventListener('unhandledrejection', (%7Breason%7D) =%3E %7B%0A  if (isError(reason)) %7B%0A    Bugsnag.notifyException(reason);%0A  %7D else if (isString(reason)) %7B%0A    Bugsnag.n
+Bugsnag.enableN
 otify
-('
 Unha
@@ -713,142 +713,10 @@
 tion
-', reason);%0A  %7D else %7B%0A    Bugsnag.notify(%0A      'UnhandledRejection',%0A      JSON.stringify(reason) %7C%7C 'No reason given',%0A    );%0A  %7D%0A%7D
+s(
 );%0A%0A

Use built-in unhandled rejection notifications in Bugsnag