mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-28 11:25:25 +03:00
⚡ Keep recent warnings in session storage
This commit is contained in:
parent
7b68af1bd4
commit
9ee4878fee
@ -1,6 +1,20 @@
|
|||||||
/* eslint no-console: ["error", { allow: ["warn", "error"] }] */
|
|
||||||
import * as Sentry from '@sentry/vue';
|
import * as Sentry from '@sentry/vue';
|
||||||
import { warningMsg } from '@/utils/CoolConsole';
|
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
|
* 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
|
* If you wish to use your own error logging service, put code for it here
|
||||||
*/
|
*/
|
||||||
const ErrorHandler = function handler(msg) {
|
const ErrorHandler = function handler(msg) {
|
||||||
warningMsg(msg);
|
warningMsg(msg); // Print to console
|
||||||
Sentry.captureMessage(`[USER-WARN] ${msg || 'Uncaptured Message'}`);
|
appendToErrorLog(msg); // Save to local storage
|
||||||
|
Sentry.captureMessage(`[USER-WARN] ${msg}`); // Report to bug tracker (if enabled)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ErrorHandler;
|
export default ErrorHandler;
|
||||||
|
Loading…
Reference in New Issue
Block a user