Do not clear global cache and refresh page on unhandled exceptions
This commit is contained in:
parent
dfd3b522cf
commit
ff78396514
@ -1,4 +1,4 @@
|
||||
import { DEBUG_ALERT_MSG, GLOBAL_STATE_CACHE_KEY } from '../config';
|
||||
import { DEBUG_ALERT_MSG } from '../config';
|
||||
import { throttle } from './schedulers';
|
||||
|
||||
window.addEventListener('error', handleErrorEvent);
|
||||
@ -6,10 +6,6 @@ window.addEventListener('unhandledrejection', handleErrorEvent);
|
||||
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
const APP_ENV = process.env.APP_ENV;
|
||||
const STARTUP_TIMEOUT = 5000;
|
||||
|
||||
const startedAt = Date.now();
|
||||
let isReloading = false;
|
||||
|
||||
function handleErrorEvent(e: ErrorEvent | PromiseRejectionEvent) {
|
||||
e.preventDefault();
|
||||
@ -23,20 +19,6 @@ export function handleError(err: Error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
|
||||
if (isReloading) {
|
||||
return;
|
||||
}
|
||||
|
||||
// For startup errors, we just clean the cache and refresh the page
|
||||
if (Date.now() - startedAt <= STARTUP_TIMEOUT && localStorage.getItem(GLOBAL_STATE_CACHE_KEY)) {
|
||||
localStorage.removeItem(GLOBAL_STATE_CACHE_KEY);
|
||||
|
||||
isReloading = true;
|
||||
window.location.reload();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (APP_ENV === 'development' || APP_ENV === 'staging') {
|
||||
throttledAlert(`${DEBUG_ALERT_MSG}\n\n${(err && err.message) || err}\n${err && err.stack}`);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user