Skip to content

Commit cd9ff6d

Browse files
committed
Protect against broken JSON packets
Closes: #163 PR-URL: #167
1 parent 0328055 commit cd9ff6d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/client.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ class Client {
6969
}
7070

7171
message(data) {
72-
const packet = JSON.parse(data);
73-
const [callType, methodName] = Object.keys(packet);
74-
const callId = packet[callType];
75-
const args = packet[methodName];
76-
this.rpc(callId, methodName, args);
72+
try {
73+
const packet = JSON.parse(data);
74+
const [callType, methodName] = Object.keys(packet);
75+
const callId = packet[callType];
76+
const args = packet[methodName];
77+
this.rpc(callId, methodName, args);
78+
} catch (err) {
79+
application.logger.error(err.message);
80+
}
7781
}
7882

7983
async rpc(callId, method, args) {

0 commit comments

Comments
 (0)