misc.mcserver: more more error handling
This commit is contained in:
parent
843bb59858
commit
daea53ca42
1 changed files with 12 additions and 4 deletions
|
@ -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);
|
||||||
|
if (dataAsString.length > 0) {
|
||||||
|
try {
|
||||||
const json = JSON.parse(dataAsString.slice(dataAsString.indexOf("{"), dataAsString.lastIndexOf("}") + 1));
|
const json = JSON.parse(dataAsString.slice(dataAsString.indexOf("{"), dataAsString.lastIndexOf("}") + 1));
|
||||||
logger.verbose("mcserver", "close", json);
|
logger.verbose("mcserver", "close", json);
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
return resolve(json);
|
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) {
|
||||||
|
|
Loading…
Reference in a new issue