fix(core): handle global script error (#8576)

This commit is contained in:
forehalo
2024-10-22 07:49:48 +00:00
parent be3125b73d
commit ff95f12d66

View File

@@ -33,23 +33,37 @@
document.body.append(errorEl); document.body.append(errorEl);
} }
function registerGlobalErrorHandler() { /**
function handler(e) { * @param event {PromiseRejectionEvent|ErrorEvent}
var error = */
'error' in e ? e.error : e.reason instanceof Error ? e.reason : null; function handler(event) {
console.error('unhandled unrecoverable error', error); var error;
const shouldCache = if ('error' in event) {
// syntax error error =
error && error instanceof SyntaxError; event.error ||
(event.message === 'Script error.'
if (!shouldCache) { ? new SyntaxError(event.message)
return; : new Error(event.message));
} } else {
error = event.reason;
e.stopImmediatePropagation();
showGlobalErrorPage();
} }
console.error('unhandled unrecoverable error', error);
var shouldCache =
// syntax error
error && error instanceof SyntaxError;
if (!shouldCache) {
return;
}
event.stopImmediatePropagation();
showGlobalErrorPage();
}
function registerGlobalErrorHandler() {
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
globalThis.addEventListener('unhandledrejection', handler); globalThis.addEventListener('unhandledrejection', handler);
globalThis.addEventListener('error', handler); globalThis.addEventListener('error', handler);