Skip to content

Commit cc5c279

Browse files
Catches HTML responses
Catches exception is API responds with a HTML document in place of JSON.
1 parent 3721d3e commit cc5c279

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ var cio = function (user, key) {
4141
text: input
4242
}}, function (err, httpResponse, body) {
4343
if (err) throw err;
44-
if (JSON.parse(body).status == "success") {
45-
callback(false, JSON.parse(body).response);
44+
try
45+
{
46+
if (JSON.parse(body).status == "success") {
47+
callback(false, JSON.parse(body).response);
48+
}
49+
else {
50+
callback(true, JSON.parse(body).status);
51+
}
4652
}
47-
else {
48-
callback(true, JSON.parse(body).status);
53+
catch(e)
54+
{
55+
console.log(e);
4956
}
5057
});
5158
}

0 commit comments

Comments
 (0)