add error handler to json parsing of translation files

This commit is contained in:
Sam Detweiler 2020-10-04 12:13:08 -05:00
parent 3dbe8bfbbf
commit 8fa96c2836

View File

@ -19,7 +19,15 @@ var Translator = (function () {
xhr.open("GET", file, true); xhr.open("GET", file, true);
xhr.onreadystatechange = function () { xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) { 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); xhr.send(null);