Browse Source

Merge pull request #585 from andreialecu/fix-cachebadresponse

Fix caching of bad langData responses
pull/629/head
Balearica 2 years ago committed by GitHub
parent
commit
66085a7d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/worker-script/index.js

6
src/worker-script/index.js

@ -99,7 +99,11 @@ const loadLanguage = async ({ @@ -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' : ''}`);

Loading…
Cancel
Save