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(); const dataAsString = totalData.toString().trim();
logger.verbose("mcserver", "data as string", dataAsString); logger.verbose("mcserver", "data as string", dataAsString);
const json = JSON.parse(dataAsString.slice(dataAsString.indexOf("{"), dataAsString.lastIndexOf("}") + 1)); if (dataAsString.length > 0) {
logger.verbose("mcserver", "close", json); try {
clearTimeout(timeout); const json = JSON.parse(dataAsString.slice(dataAsString.indexOf("{"), dataAsString.lastIndexOf("}") + 1));
return resolve(json); 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 () {}); client.on("timeout", function () {});
} catch (err) { } catch (err) {