From 8fa96c2836d0fee0a6d68e990587a1e2d0ba3cd3 Mon Sep 17 00:00:00 2001 From: Sam Detweiler Date: Sun, 4 Oct 2020 12:13:08 -0500 Subject: [PATCH] add error handler to json parsing of translation files --- js/translator.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/translator.js b/js/translator.js index 0f4bc00a..43b65297 100644 --- a/js/translator.js +++ b/js/translator.js @@ -19,7 +19,15 @@ var Translator = (function () { xhr.open("GET", file, true); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { - callback(JSON.parse(xhr.responseText)); + // needs error handler try/catch at least + let fileinfo = null; + try { + fileinfo = JSON.parse(xhr.responseText); + } catch (exception) { + // nothing here, but don't die + console.log(" loading json file failed =" + file); + } + callback(fileinfo); } }; xhr.send(null);