From 7dd510a6594fe4ed659aa90b6205b2dab5dfcb83 Mon Sep 17 00:00:00 2001 From: Euan Date: Sun, 18 May 2014 14:45:38 -0400 Subject: [PATCH] Handle invalid json --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5d8db48..f87a5d2 100644 --- a/index.js +++ b/index.js @@ -20,8 +20,13 @@ var hn = { request(query, function (error, response, body) { if (!error && response.statusCode != 200) error = response.statusCode; - if (typeof body !== 'undefined') - body = JSON.parse(body); + if (typeof body !== 'undefined') { + try { + body = JSON.parse(body); + } catch(ex) { + if(!error) error = ex; + } + } cb(error, body); }); },