Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request natevw#2 from willwhite/json-parse
Stricter JSON parse when content-type header is application/json.
  • Loading branch information
natevw committed Dec 5, 2012
2 parents bec26a1 + ad91cde commit 61b60cc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions chargify.js
Expand Up @@ -28,9 +28,13 @@ Chargify.prototype.request = function(options, callback) {
};
request(options, function(err, res, body) {
if (err) return callback(err);
try {
var body = JSON.parse(body);
} catch(e) {}
if (res.headers['content-type'].indexOf('application/json') !== -1 && typeof body !== 'object') {
try {
res.body = body = JSON.parse(body);
} catch(e) {
return callback(e);
}
}
callback(err, res, body);
});
};
Expand Down

0 comments on commit 61b60cc

Please sign in to comment.