mirror of https://github.com/halo-dev/halo
feat: handling front-end plugin loading failure exceptions
Signed-off-by: Ryan Wang <i@ryanc.cc>pull/3445/head
parent
28367a0c81
commit
66c1cb69b2
16
src/main.ts
16
src/main.ts
|
@ -100,6 +100,8 @@ function loadStyle(href: string) {
|
|||
});
|
||||
}
|
||||
|
||||
const pluginErrorMessages: Array<string> = [];
|
||||
|
||||
async function loadPluginModules() {
|
||||
const { data } =
|
||||
await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin();
|
||||
|
@ -116,6 +118,7 @@ async function loadPluginModules() {
|
|||
};
|
||||
|
||||
if (entry) {
|
||||
try {
|
||||
const { load } = useScriptTag(
|
||||
`${import.meta.env.VITE_API_URL}${plugin.status?.entry}`
|
||||
);
|
||||
|
@ -127,18 +130,29 @@ async function loadPluginModules() {
|
|||
plugin.spec.module = pluginModule;
|
||||
registerModule(pluginModule);
|
||||
}
|
||||
} catch (e) {
|
||||
const message = `${plugin.metadata.name}: Failed load plugin entry module`;
|
||||
console.error(message, e);
|
||||
pluginErrorMessages.push(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (stylesheet) {
|
||||
try {
|
||||
await loadStyle(`${import.meta.env.VITE_API_URL}${stylesheet}`);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
const message = `${plugin.metadata.name}: Failed load plugin stylesheet`;
|
||||
console.error(message, e);
|
||||
pluginErrorMessages.push(message);
|
||||
}
|
||||
}
|
||||
|
||||
pluginStore.registerPlugin(plugin);
|
||||
}
|
||||
|
||||
if (pluginErrorMessages.length > 0) {
|
||||
alert(pluginErrorMessages.join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCurrentUser() {
|
||||
|
|
Loading…
Reference in New Issue