Don't crash when parsing malformed JSON

This commit is contained in:
RobinLinus 2019-05-29 21:35:39 +02:00 committed by GitHub
parent 72bb4cba1f
commit 993b484396
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,8 +26,13 @@ class SnapdropServer {
} }
_onMessage(sender, message) { _onMessage(sender, message) {
message = JSON.parse(message); // Try to parse message
try {
message = JSON.parse(message);
} catch (e) {
return; // TODO: handle malformed JSON
}
switch (message.type) { switch (message.type) {
case 'disconnect': case 'disconnect':
this._leaveRoom(sender); this._leaveRoom(sender);
@ -221,4 +226,4 @@ class Peer {
}; };
} }
const server = new SnapdropServer(process.env.PORT || 3000); const server = new SnapdropServer(process.env.PORT || 3000);