From 2e38d403b3c9b76fc4ef46b52bb40669e811ad2b Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Tue, 5 Jul 2022 13:14:20 +1000 Subject: [PATCH] fix(web): only report console errors if _enabled --- common/core/web/tools/sentry-manager/src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/core/web/tools/sentry-manager/src/index.ts b/common/core/web/tools/sentry-manager/src/index.ts index a3b0a3c6fa..9434871a24 100644 --- a/common/core/web/tools/sentry-manager/src/index.ts +++ b/common/core/web/tools/sentry-manager/src/index.ts @@ -184,10 +184,14 @@ namespace com.keyman { initConsole() { // creating function declarations for better stacktraces (otherwise they'd be anonymous function expressions) let oldConsoleError = console.error; + let _this = this; + // Note that Sentry may have overridden console.error so we are re-overriding it here post-init. console.error = reportingConsoleError; // defined via function hoisting function reportingConsoleError() { let args = Array.prototype.slice.call(arguments); - Sentry.captureException(reduceConsoleArgs(args), { level: 'error' }); + if(_this._enabled) { + Sentry.captureException(reduceConsoleArgs(args), { level: 'error' }); + } return oldConsoleError.apply(console, args); }; @@ -195,7 +199,9 @@ namespace com.keyman { console.warn = reportingConsoleWarn; // defined via function hoisting function reportingConsoleWarn() { let args = Array.prototype.slice.call(arguments); - Sentry.captureMessage(reduceConsoleArgs(args), { level: 'warning' }); + if(_this._enabled) { + Sentry.captureMessage(reduceConsoleArgs(args), { level: 'warning' }); + } return oldConsoleWarn.apply(console, args); }