From 106e20a2db858b0dcf8c03fc9ec12283b8363e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Tainon?= Date: Mon, 6 May 2024 15:50:45 +0200 Subject: [PATCH] [Fix] Add reject handler if script is not loaded correctly --- frontend/task/libs/import_modules.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/task/libs/import_modules.ts b/frontend/task/libs/import_modules.ts index 26285ef2..ca6d0a63 100644 --- a/frontend/task/libs/import_modules.ts +++ b/frontend/task/libs/import_modules.ts @@ -310,8 +310,8 @@ async function importModules(modulesList, modulesPath) { if(curModule.type == 'stylesheet') { getStyle(modSrc, modId, modClass); } else { - await new Promise(resolve => { - getScript(modSrc, modId, modClass, resolve); + await new Promise((resolve, reject) => { + getScript(modSrc, modId, modClass, resolve, reject); }); } } else { @@ -362,7 +362,7 @@ export function getJsLibLoaded() { return jsLibLoaded; } -function getScript(modSrc, modId, modClass, callback) { +function getScript(modSrc, modId, modClass, callback, reject) { let script = document.createElement('script'); script.setAttribute('type', 'text/javascript'); script.setAttribute('id', modId); @@ -380,6 +380,9 @@ function getScript(modSrc, modId, modClass, callback) { if(!isAbort && callback) setTimeout(callback, 0); } }; + script.onerror = () => { + reject(`Unable to load module "${modId}" (${modSrc})`); + } script.src = modSrc; head.appendChild(script);