From cc5c279b9f174ce16de1f6a615208b5304e18d98 Mon Sep 17 00:00:00 2001 From: CoderDecoder01 Date: Wed, 12 Jul 2017 20:53:25 +0530 Subject: [PATCH] Catches HTML responses Catches exception is API responds with a HTML document in place of JSON. --- app.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 325f36d..dbfcfba 100644 --- a/app.js +++ b/app.js @@ -41,11 +41,18 @@ var cio = function (user, key) { text: input }}, function (err, httpResponse, body) { if (err) throw err; - if (JSON.parse(body).status == "success") { - callback(false, JSON.parse(body).response); + try + { + if (JSON.parse(body).status == "success") { + callback(false, JSON.parse(body).response); + } + else { + callback(true, JSON.parse(body).status); + } } - else { - callback(true, JSON.parse(body).status); + catch(e) + { + console.log(e); } }); }