Skip to content

Commit

Permalink
Merge pull request #483 from France-ioi/fix-import-modules
Browse files Browse the repository at this point in the history
[Fix] Add reject handler if script is not loaded correctly
  • Loading branch information
SebastienTainon authored May 6, 2024
2 parents d301607 + 106e20a commit e853d75
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions frontend/task/libs/import_modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e853d75

Please sign in to comment.