Skip to content

Commit

Permalink
Merge pull request #2 from euank/master
Browse files Browse the repository at this point in the history
Handle invalid json
  • Loading branch information
christianbundy committed May 18, 2014
2 parents 4d4ebf4 + 7dd510a commit b701d95
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},
Expand Down

0 comments on commit b701d95

Please sign in to comment.