Skip to content

Commit b701d95

Browse files
Merge pull request #2 from euank/master
Handle invalid json
2 parents 4d4ebf4 + 7dd510a commit b701d95

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ var hn = {
2020
request(query, function (error, response, body) {
2121
if (!error && response.statusCode != 200)
2222
error = response.statusCode;
23-
if (typeof body !== 'undefined')
24-
body = JSON.parse(body);
23+
if (typeof body !== 'undefined') {
24+
try {
25+
body = JSON.parse(body);
26+
} catch(ex) {
27+
if(!error) error = ex;
28+
}
29+
}
2530
cb(error, body);
2631
});
2732
},

0 commit comments

Comments
 (0)