Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save samoshkin/06a9c5f5aba6ee521572814bf46aa410 to your computer and use it in GitHub Desktop.
Save samoshkin/06a9c5f5aba6ee521572814bf46aa410 to your computer and use it in GitHub Desktop.
Conditionally build an array using if..else blocks
const deployment = {
debug: process.env.NODE_ENV === 'development',
};
const defaultIntegrations = integrations.filter(x => x.name !== 'Dedupe');
const integrations = [
// add all the default integrations but those which were excluded using spread syntax
...defaultIntegrations,
// Extracts all non-native attributes from the Error object and attaches them to the event as the extra data
new ExtraErrorDataIntegration(),
];
if (deployment.debug) {
// print event to DevTools console before sending it to Sentry
// enable this integration only in DEBUG mode
integrations.push(new DebugIntegration());
// send all console.log() messages to Sentry in DEBUG mode
integrations.push(new CaptureConsoleIntegration());
}
if (!deployment.debug) {
// in RELEASE mode
// Uses the web browser's online and offline events to detect when no network connectivity is available.
// If offline, it saves events to the web browser's client-side storage (typically IndexedDB),
// then automatically uploads events when network connectivity is restored.
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/Online_and_offline_events
integrations.push(new OfflineIntegration());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment