Skip to content

Commit

Permalink
Merge pull request #585 from andreialecu/fix-cachebadresponse
Browse files Browse the repository at this point in the history
Fix caching of bad langData responses
  • Loading branch information
Balearica authored Aug 9, 2022
2 parents adcb5b8 + 01e8335 commit 66085a7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/worker-script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ const loadLanguage = async ({
}

if (path !== null) {
const resp = await (isWebWorker ? fetch : adapter.fetch)(`${path}/${lang}.traineddata${gzip ? '.gz' : ''}`);
const fetchUrl = `${path}/${lang}.traineddata${gzip ? '.gz' : ''}`;
const resp = await (isWebWorker ? fetch : adapter.fetch)(fetchUrl);
if (!resp.ok) {
throw Error(`Network error while fetching ${fetchUrl}. Response code: ${resp.status}`)
}
data = await resp.arrayBuffer();
} else {
data = await adapter.readCache(`${langPath}/${lang}.traineddata${gzip ? '.gz' : ''}`);
Expand Down

0 comments on commit 66085a7

Please sign in to comment.