Skip to content

Commit

Permalink
check statusCode before parsing body
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Hindley committed Jun 30, 2015
1 parent a515bfe commit d30d74a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ function got(url, opts, cb) {
readAllStream(res, encoding, function (err, data) {
if (err) {
err = new GotError('Reading ' + url + ' response failed', err);
} else if (data && json) {
} else if (json && statusCode !== 204) {
// only parse json if the option is enabled, and the response
// is not a 204 (empty reponse)
try {
data = JSON.parse(data);
} catch (e) {
Expand Down

0 comments on commit d30d74a

Please sign in to comment.