Don't crash when parsing malformed JSON
This commit is contained in:
parent
72bb4cba1f
commit
993b484396
1 changed files with 8 additions and 3 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue