Add workaround for 429 Too Many Requests
Firefox has an annoying bug that they refuse to fix where returning a valid 429 response is considered an aborted connection. Firefox makes no additional attempts at retrying, no matter what the request may have been. Chromium and even Internet Explorer handle this correctly.
This commit is contained in:
+26
-3
@@ -74,9 +74,32 @@ async function initializeHighlightJS() {
|
|||||||
let langs = [];
|
let langs = [];
|
||||||
for (let lang of languages) {
|
for (let lang of languages) {
|
||||||
console.log(`highlight.JS: Importing language definition for '${lang}'...`);
|
console.log(`highlight.JS: Importing language definition for '${lang}'...`);
|
||||||
langs.push(import(`./highlightjs/languages/${lang}.min.js`).then((mod) => {
|
langs.push(new Promise(async (resolve, reject) => {
|
||||||
window.highlightJS.registerLanguage(lang, mod.default);
|
const start = performance.now();
|
||||||
console.log(`highlight.JS: Imported language definition for '${lang}'.`);
|
const max_attempts = 5;
|
||||||
|
let attempt = 0;
|
||||||
|
|
||||||
|
let mod = undefined;
|
||||||
|
let err = null;
|
||||||
|
for (let attempt = 1; attempt <= 5; attempt++) {
|
||||||
|
try {
|
||||||
|
mod = await import(`./highlightjs/languages/${lang}.min.js`);
|
||||||
|
break;
|
||||||
|
} catch(ex) {
|
||||||
|
err = ex;
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {resolve()}, 1000);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mod) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
window.highlightJS.registerLanguage(lang, mod.default);
|
||||||
|
console.log(`highlight.JS: Imported language definition for '${lang}' after ${(performance.now() - start).toFixed(2)}ms.`);
|
||||||
|
resolve(mod);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
await Promise.allSettled(langs)
|
await Promise.allSettled(langs)
|
||||||
|
|||||||
Reference in New Issue
Block a user