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:
Michael Fabian 'Xaymar' Dirks
2024-06-02 06:24:10 +02:00
parent 3b410cf30a
commit 3f0782d1cf
+25 -2
View File
@@ -74,9 +74,32 @@ async function initializeHighlightJS() {
let langs = [];
for (let lang of languages) {
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) => {
const start = performance.now();
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}'.`);
console.log(`highlight.JS: Imported language definition for '${lang}' after ${(performance.now() - start).toFixed(2)}ms.`);
resolve(mod);
}
}));
}
await Promise.allSettled(langs)