Catch JSON parse errors

This commit is contained in:
Tulir Asokan 2020-08-18 17:05:53 +03:00
parent dd16b3d461
commit 938068703b
1 changed files with 8 additions and 3 deletions

View File

@ -149,10 +149,15 @@ export default class Client {
this.log("Ignoring line, client is stopped") this.log("Ignoring line, client is stopped")
return return
} }
const req = JSON.parse(line) let req
try {
req = JSON.parse(line)
} catch (err) {
this.log("Non-JSON request:", line)
return
}
if (!req.command || !req.id) { if (!req.command || !req.id) {
console.log("Invalid request, terminating", this.connID) this.log("Invalid request:", line)
await this.stop()
return return
} }
if (req.id <= this.maxCommandID) { if (req.id <= this.maxCommandID) {