upd: lib.ws-client (Manage JSON parsing on message received)

This commit is contained in:
xdrm-brackets 2017-12-04 10:31:11 +01:00
parent a2746b6275
commit b66bafb3c3
1 changed files with 13 additions and 2 deletions

View File

@ -132,8 +132,19 @@ class WSClient{
return; return;
} }
/* (3) If all right -> success */ /* (3) Try to JSON parse */
this.on_receive(msg_event.data, null); var parsedMsg = null;
try{
parsedMsg = JSON.parse(msg_event.data);
}catch(e){
this.on_receive(null, 'JSON error');
return;
}
/* (4) If all right -> success */
this.on_receive(parsedMsg, null);
} }