Skip to content

Commit

Permalink
Add try/catch in very rare scenario of html being returned instead of…
Browse files Browse the repository at this point in the history
… json. this 90% appears to be because of a timeout blip recently
  • Loading branch information
motdotla committed Oct 1, 2013
1 parent 31435af commit a69e95d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/sendgrid.js
Expand Up @@ -79,8 +79,15 @@ var Sendgrid = function(api_user, api_key, options) {
method : 'POST',
uri : "https://sendgrid.com/api/mail.send.json"
}, function(err, resp, body) {
var json;

if(err) return callback(err, null);
var json = JSON.parse(body);

try {
json = JSON.parse(body);
} catch (e) {
return callback(new Error(e), null);
}

if (json.message !== 'success') {
var error = 'sendgrid error';
Expand Down

0 comments on commit a69e95d

Please sign in to comment.