🎨 uniformed error message (#1580)

This commit is contained in:
Troy Li 2021-07-19 15:45:08 +08:00 committed by GitHub
parent 438778d8d9
commit f00f2ca655
2 changed files with 16 additions and 16 deletions

5
src/error.ts Normal file
View File

@ -0,0 +1,5 @@
export class QiankunError extends Error {
constructor(message: string) {
super(`[qiankun]: ${message}`);
}
}

View File

@ -7,6 +7,7 @@ import { importEntry } from 'import-html-entry';
import { concat, forEach, mergeWith } from 'lodash';
import type { LifeCycles, ParcelConfigObject } from 'single-spa';
import getAddOns from './addons';
import { QiankunError } from './error';
import { getMicroAppStateActions } from './globalState';
import type {
FrameworkConfiguration,
@ -33,10 +34,10 @@ import {
function assertElementExist(element: Element | null | undefined, msg?: string) {
if (!element) {
if (msg) {
throw new Error(msg);
throw new QiankunError(msg);
}
throw new Error('[qiankun] element not existed!');
throw new QiankunError('element not existed!');
}
}
@ -118,22 +119,16 @@ function getAppWrapperGetter(
) {
return () => {
if (useLegacyRender) {
if (strictStyleIsolation) throw new Error('[qiankun]: strictStyleIsolation can not be used with legacy render!');
if (scopedCSS) throw new Error('[qiankun]: experimentalStyleIsolation can not be used with legacy render!');
if (strictStyleIsolation) throw new QiankunError('strictStyleIsolation can not be used with legacy render!');
if (scopedCSS) throw new QiankunError('experimentalStyleIsolation can not be used with legacy render!');
const appWrapper = document.getElementById(getWrapperId(appInstanceId));
assertElementExist(
appWrapper,
`[qiankun] Wrapper element for ${appName} with instance ${appInstanceId} is not existed!`,
);
assertElementExist(appWrapper, `Wrapper element for ${appName} with instance ${appInstanceId} is not existed!`);
return appWrapper!;
}
const element = elementGetter();
assertElementExist(
element,
`[qiankun] Wrapper element for ${appName} with instance ${appInstanceId} is not existed!`,
);
assertElementExist(element, `Wrapper element for ${appName} with instance ${appInstanceId} is not existed!`);
if (strictStyleIsolation && supportShadowDOM) {
return element!.shadowRoot!;
@ -178,13 +173,13 @@ function getRender(appName: string, appContent: string, legacyRender?: HTMLConte
switch (phase) {
case 'loading':
case 'mounting':
return `[qiankun] Target container with ${container} not existed while ${appName} ${phase}!`;
return `Target container with ${container} not existed while ${appName} ${phase}!`;
case 'mounted':
return `[qiankun] Target container with ${container} not existed after ${appName} ${phase}!`;
return `Target container with ${container} not existed after ${appName} ${phase}!`;
default:
return `[qiankun] Target container with ${container} not existed while ${appName} rendering!`;
return `Target container with ${container} not existed while ${appName} rendering!`;
}
})();
assertElementExist(containerElement, errorMsg);
@ -239,7 +234,7 @@ function getLifecyclesFromExports(
return globalVariableExports;
}
throw new Error(`[qiankun] You need to export lifecycle functions in ${appName} entry`);
throw new QiankunError(`You need to export lifecycle functions in ${appName} entry`);
}
let prevAppUnmountedDeferred: Deferred<void>;