Skip to content
Snippets Groups Projects
Commit ac7df9d8 authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer Committed by Jan-Hendrik Willms
Browse files

Re-throw error when failing to load a chunk.

Closes #4287

Merge request studip/studip!3103
parent 8cfd8940
No related branches found
No related tags found
No related merge requests found
...@@ -8,13 +8,19 @@ export const loadScript = function (script_name) { ...@@ -8,13 +8,19 @@ export const loadScript = function (script_name) {
}); });
}; };
export const loadChunk = (function () { let mathjax_promise = null;
var mathjax_promise = null;
return function (chunk) { /** This function dynamically loads JS features organized in chunks.
var promise = null; *
* @param {string} chunk The name of the chunk to load.
* @param {{ silent: boolean }} options Options for loading the chunk.
* Pass `{ silent: true }` to supress
* error messages.
* @return {Promise}
*/
export const loadChunk = function (chunk, { silent = false } = {}) {
let promise = null;
switch (chunk) { switch (chunk) {
case 'code-highlight': case 'code-highlight':
promise = import( promise = import(
/* webpackChunkName: "code-highlight" */ /* webpackChunkName: "code-highlight" */
...@@ -47,21 +53,18 @@ export const loadChunk = (function () { ...@@ -47,21 +53,18 @@ export const loadChunk = (function () {
case 'mathjax': case 'mathjax':
if (mathjax_promise === null) { if (mathjax_promise === null) {
mathjax_promise = STUDIP.loadScript( mathjax_promise = STUDIP.loadScript('javascripts/mathjax/MathJax.js?config=TeX-AMS_HTML,default')
'javascripts/mathjax/MathJax.js?config=TeX-AMS_HTML,default' .then(() => {
).then(() => {
(function (origPrint) { (function (origPrint) {
window.print = function () { window.print = function () {
window.MathJax.Hub.Queue( window.MathJax.Hub.Queue(['Delay', window.MathJax.Callback, 700], origPrint);
['Delay', window.MathJax.Callback, 700],
origPrint
);
}; };
})(window.print); })(window.print);
return window.MathJax; return window.MathJax;
}).catch(() => { })
console.log('Could not load mathjax') .catch(() => {
throw new Error('Could not load mathjax');
}); });
} }
promise = mathjax_promise; promise = mathjax_promise;
...@@ -86,7 +89,9 @@ export const loadChunk = (function () { ...@@ -86,7 +89,9 @@ export const loadChunk = (function () {
} }
return promise.catch((error) => { return promise.catch((error) => {
if (!silent) {
console.error(`Could not load chunk ${chunk}`, error); console.error(`Could not load chunk ${chunk}`, error);
}
throw error;
}); });
}; };
}());
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment