From 9ee4878feec15ad7d5e55520be74d723f6e00b8b Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 12 Sep 2021 15:59:42 +0100 Subject: [PATCH] :zap: Keep recent warnings in session storage --- src/utils/ErrorHandler.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/utils/ErrorHandler.js b/src/utils/ErrorHandler.js index f2a6a2e2..f430fa74 100644 --- a/src/utils/ErrorHandler.js +++ b/src/utils/ErrorHandler.js @@ -1,6 +1,20 @@ -/* eslint no-console: ["error", { allow: ["warn", "error"] }] */ import * as Sentry from '@sentry/vue'; import { warningMsg } from '@/utils/CoolConsole'; +import { sessionStorageKeys } from '@/utils/defaults'; + +/* Makes the current time, like hh:mm:ss */ +const makeTime = () => { + const now = new Date(); + const pad = (digit) => String(digit).padStart(2, '0'); + return `${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`; +}; + +/* Appends recent errors to local storage, for viewing in the UI */ +const appendToErrorLog = (msg) => { + let errorLog = sessionStorage.getItem(sessionStorageKeys.ERROR_LOG) || ''; + errorLog += `[${makeTime()}] ${msg}\n`; + sessionStorage.setItem(sessionStorageKeys.ERROR_LOG, errorLog); +}; /** * Function called when an error happens @@ -9,8 +23,9 @@ import { warningMsg } from '@/utils/CoolConsole'; * If you wish to use your own error logging service, put code for it here */ const ErrorHandler = function handler(msg) { - warningMsg(msg); - Sentry.captureMessage(`[USER-WARN] ${msg || 'Uncaptured Message'}`); + warningMsg(msg); // Print to console + appendToErrorLog(msg); // Save to local storage + Sentry.captureMessage(`[USER-WARN] ${msg}`); // Report to bug tracker (if enabled) }; export default ErrorHandler;