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
34
src/main.ts
34
src/main.ts
|
@ -100,6 +100,8 @@ function loadStyle(href: string) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pluginErrorMessages: Array<string> = [];
|
||||||
|
|
||||||
async function loadPluginModules() {
|
async function loadPluginModules() {
|
||||||
const { data } =
|
const { data } =
|
||||||
await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin();
|
await apiClient.extension.plugin.listpluginHaloRunV1alpha1Plugin();
|
||||||
|
@ -116,16 +118,22 @@ async function loadPluginModules() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
const { load } = useScriptTag(
|
try {
|
||||||
`${import.meta.env.VITE_API_URL}${plugin.status?.entry}`
|
const { load } = useScriptTag(
|
||||||
);
|
`${import.meta.env.VITE_API_URL}${plugin.status?.entry}`
|
||||||
await load();
|
);
|
||||||
const pluginModule = window[plugin.metadata.name];
|
await load();
|
||||||
|
const pluginModule = window[plugin.metadata.name];
|
||||||
|
|
||||||
if (pluginModule) {
|
if (pluginModule) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
plugin.spec.module = pluginModule;
|
plugin.spec.module = pluginModule;
|
||||||
registerModule(pluginModule);
|
registerModule(pluginModule);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
const message = `${plugin.metadata.name}: Failed load plugin entry module`;
|
||||||
|
console.error(message, e);
|
||||||
|
pluginErrorMessages.push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,12 +141,18 @@ async function loadPluginModules() {
|
||||||
try {
|
try {
|
||||||
await loadStyle(`${import.meta.env.VITE_API_URL}${stylesheet}`);
|
await loadStyle(`${import.meta.env.VITE_API_URL}${stylesheet}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
const message = `${plugin.metadata.name}: Failed load plugin stylesheet`;
|
||||||
|
console.error(message, e);
|
||||||
|
pluginErrorMessages.push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginStore.registerPlugin(plugin);
|
pluginStore.registerPlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pluginErrorMessages.length > 0) {
|
||||||
|
alert(pluginErrorMessages.join("\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCurrentUser() {
|
async function loadCurrentUser() {
|
||||||
|
|
Loading…
Reference in New Issue