Skip to content

Commit

Permalink
Properly catch JSON parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cletusc committed Nov 11, 2014
1 parent f8fe986 commit 67bc939
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ TwitchAPI.prototype.api = function (path, options, callback) {
if (error) {
return callback.call(self, error);
}
return callback.call(self, null, response.statusCode, (options.json ? JSON.parse(body) : body));
if (options.json) {
try {
body = JSON.parse(body);
}
catch (error) {
return callback.call(self, error);
}
}
return callback.call(self, null, response.statusCode, body);
});

return this;
Expand Down

0 comments on commit 67bc939

Please sign in to comment.