Ensure message format availability

Make sure the entire process doesn't crash when a message is sent without `type` and/or `data` as such:

```
error: Uncaught Exception TypeError: Cannot read property 'id' of undefined
    at Server.gotData (/usr/src/app/node_modules/@trail/pigeoneer/node_modules/node-ipc/dao/socketServer.js:181:24)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at Socket.EventEmitter.emit (/usr/src/app/node_modules/@trail/pigeoneer/node_modules/sc-domain/index.js:12:31)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)
```
This commit is contained in:
Melvin 2016-11-15 15:17:54 +01:00 committed by GitHub
parent e7739111fc
commit 8de357f488

View file

@ -176,6 +176,11 @@ function gotData(socket,data,UDPSocket){
let message=new Message;
message.load(data.shift());
// In case either `type` or `data` is missing we won't process this message.
if (!message.type || !message.data) {
continue;
}
this.log('received event of : ',message.type,message.data);
if(message.data.id){