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();
|
||||
logger.verbose("mcserver", "data as string", dataAsString);
|
||||
const json = JSON.parse(dataAsString.slice(dataAsString.indexOf("{"), dataAsString.lastIndexOf("}") + 1));
|
||||
logger.verbose("mcserver", "close", json);
|
||||
clearTimeout(timeout);
|
||||
return resolve(json);
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue