Don't crash server on reading metadata

This commit is contained in:
SillyLossy
2023-04-09 15:03:59 +03:00
parent 8ba3984a46
commit 658a26def2

View File

@@ -705,8 +705,8 @@ app.post("/getcharacters", jsonParser, function (request, response) {
var i = 0;
pngFiles.forEach(item => {
//console.log(item);
var img_data = charaRead(charactersPath + item);
try {
var img_data = charaRead(charactersPath + item);
let jsonObject = JSON.parse(img_data);
jsonObject.avatar = item;
//console.log(jsonObject);
@@ -714,6 +714,7 @@ app.post("/getcharacters", jsonParser, function (request, response) {
characters[i] = jsonObject;
i++;
} catch (error) {
console.log(`Could not read character: ${item}`);
if (error instanceof SyntaxError) {
console.log("String [" + (i) + "] is not valid JSON!");
} else {