diff --git a/chargify.js b/chargify.js index 3ade510..584c571 100644 --- a/chargify.js +++ b/chargify.js @@ -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); }); };