From 01e833576807e3b7ab1337634db805c26498b6bd Mon Sep 17 00:00:00 2001 From: Andrei Alecu Date: Thu, 25 Nov 2021 18:42:21 +0200 Subject: [PATCH] Fix caching of bad langData responses Fixes #584 --- src/worker-script/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/worker-script/index.js b/src/worker-script/index.js index 6507bf1..c0c0fa0 100644 --- a/src/worker-script/index.js +++ b/src/worker-script/index.js @@ -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' : ''}`);