From 9359758ce631528ae2b0deb82df05f908d5c42a2 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 22 Jun 2018 18:07:06 +0200 Subject: why is this double encoded --- app/client/socket/socket.task.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'app/client/socket') diff --git a/app/client/socket/socket.task.js b/app/client/socket/socket.task.js index 77f1310..1b33cd9 100644 --- a/app/client/socket/socket.task.js +++ b/app/client/socket/socket.task.js @@ -5,9 +5,23 @@ import { socket } from './socket.connection' let finishTimeout; -socket.on('task_res', (data) => { +socket.on('task_res', (raw_data) => { // does not like the nested task object for some reason.. - data = JSON.parse(data) + console.log(typeof raw_data) + let data; + try { + if (typeof raw_data === 'string') { + data = JSON.parse(raw_data) + if (typeof data === 'string') { + data = JSON.parse(data) + } + } else { + data = raw_data + } + } catch (e) { + console.warn('problem with json', e) + return + } if (data.task) { dispatch({ type: types.task.update, data: data.task }) } -- cgit v1.2.3-70-g09d2