misc.mcserver: more more error handling

This commit is contained in:
Cynthia Foxwell 2024-08-02 12:05:23 -06:00
parent 843bb59858
commit daea53ca42

View file

@ -135,10 +135,18 @@ function queryServer(ip, port, HANDSHAKE_PACKET) {
}
const dataAsString = totalData.toString().trim();
logger.verbose("mcserver", "data as string", dataAsString);
if (dataAsString.length > 0) {
try {
const json = JSON.parse(dataAsString.slice(dataAsString.indexOf("{"), dataAsString.lastIndexOf("}") + 1));
logger.verbose("mcserver", "close", json);
clearTimeout(timeout);
return resolve(json);
} catch (err) {
return resolve({error: err});
}
} else {
return resolve({error: new Error("Server returned no data.")});
}
});
client.on("timeout", function () {});
} catch (err) {