From d44748fcad6e353839295d6b9dd17419a329ab47 Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Mon, 11 Jan 2021 13:17:41 +0100 Subject: [PATCH] feat: make error reporting opt-in --- .../javascripts/directives/views/accountMenu.ts | 2 +- app/assets/javascripts/services/errorReporting.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/directives/views/accountMenu.ts b/app/assets/javascripts/directives/views/accountMenu.ts index 8f1e0b757..7d73e82ab 100644 --- a/app/assets/javascripts/directives/views/accountMenu.ts +++ b/app/assets/javascripts/directives/views/accountMenu.ts @@ -100,7 +100,7 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> { }, mutable: {}, showBetaWarning: false, - errorReportingEnabled: !storage.get(StorageKey.DisableErrorReporting), + errorReportingEnabled: storage.get(StorageKey.DisableErrorReporting) === false, showSessions: false, } as AccountMenuState; } diff --git a/app/assets/javascripts/services/errorReporting.ts b/app/assets/javascripts/services/errorReporting.ts index 50c439db5..0a309e3ab 100644 --- a/app/assets/javascripts/services/errorReporting.ts +++ b/app/assets/javascripts/services/errorReporting.ts @@ -1,4 +1,4 @@ -import { SNLog } from '@standardnotes/snjs'; +import { isNullOrUndefined, SNLog } from '@standardnotes/snjs'; import { isDesktopApplication, isDev } from '@/utils'; import { storage, StorageKey } from './localStorage'; import Bugsnag from '@bugsnag/js'; @@ -6,6 +6,7 @@ import Bugsnag from '@bugsnag/js'; declare const __VERSION__: string; declare global { interface Window { + // eslint-disable-next-line camelcase _bugsnag_api_key?: string; } } @@ -21,8 +22,15 @@ function redactFilePath(line: string): string { } export function startErrorReporting() { + const disableErrorReporting = storage.get(StorageKey.DisableErrorReporting); if ( - storage.get(StorageKey.DisableErrorReporting) || + /** + * Error reporting used to be opt-out, but is now opt-in, so + * treat the absence of an error reporting preference as an indication + * to disable error reporting. + */ + isNullOrUndefined(disableErrorReporting) || + disableErrorReporting || !window._bugsnag_api_key ) { SNLog.onError = console.error;