From 19204b5c1c8c4e63c3c077a0b3ef05c984ecd80a Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Sat, 4 Mar 2017 08:59:52 +0100 Subject: [PATCH] added json parse error catch in shepherd get cache --- routes/shepherd.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index b672399..3b3dd84 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -117,9 +117,17 @@ shepherd.get('/cache', function(req, res, next) { res.end(JSON.stringify(errorObj)); } else { + var parsedJSON = 'JSON parse error'; + + try { + parsedJSON = JSON.parse(data); + } catch (e) { + console.log('JSON parse error'); + } + var successObj = { 'msg': 'success', - 'result': data ? JSON.parse(data) : '' + 'result': parsedJSON }; res.end(JSON.stringify(successObj));