Skip to content

Commit

Permalink
Handle case where res.headers['content-type’] is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
newyorkpizza authored and newyorkpizza committed Jan 26, 2017
1 parent d98226a commit 7e0a403
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ Request.prototype.handleResponse = function (res) {
// FIXME: An ugly hack to overcome invalid response type in mailgun api (see http://bit.ly/1eF30fU).
// We skip content-type validation for 'campaings' endpoint assuming it is JSON.
var skipContentTypeCheck = res.req && res.req.path && res.req.path.match(/\/campaigns/);
if (chunks && !error && (skipContentTypeCheck || (res.headers['content-type'].indexOf('application/json') >= 0))) {
var isJSON = res.headers['content-type'] && res.headers['content-type'].indexOf('application/json') >= 0;
if (chunks && !error && (skipContentTypeCheck || isJSON)) {
try {
body = JSON.parse(chunks);
} catch (e) {
Expand Down

0 comments on commit 7e0a403

Please sign in to comment.