diff options
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r-- | lib/sendgrid.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/sendgrid.js b/lib/sendgrid.js index cda5525..5f1260b 100644 --- a/lib/sendgrid.js +++ b/lib/sendgrid.js @@ -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'; |