fix(core): handle global script error (#8576)
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user