From b66bafb3c348c5d69f50fd5bd20c8e25b8b7cb04 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 4 Dec 2017 10:31:11 +0100 Subject: [PATCH] upd: lib.ws-client (Manage JSON parsing on message received) --- view/lib/ws-client-es6.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/view/lib/ws-client-es6.js b/view/lib/ws-client-es6.js index 5d95fe0..bf8a357 100644 --- a/view/lib/ws-client-es6.js +++ b/view/lib/ws-client-es6.js @@ -132,8 +132,19 @@ class WSClient{ return; } - /* (3) If all right -> success */ - this.on_receive(msg_event.data, null); + /* (3) Try to JSON parse */ + 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); }