summaryrefslogtreecommitdiffstats
path: root/lib/sendgrid.js
diff options
context:
space:
mode:
authorscottmotte <scott@scottmotte.com>2013-10-01 13:58:57 -0500
committerscottmotte <scott@scottmotte.com>2013-10-01 13:58:57 -0500
commita69e95dc86cb70111e4cf545225b453501fa58d6 (patch)
treee19737a052e7eeee7982b47a902701efdc340023 /lib/sendgrid.js
parent31435aff2efbd0724de2f213ce8e678b0a5a9232 (diff)
downloadsendgrid-nodejs-a69e95dc86cb70111e4cf545225b453501fa58d6.zip
sendgrid-nodejs-a69e95dc86cb70111e4cf545225b453501fa58d6.tar.gz
sendgrid-nodejs-a69e95dc86cb70111e4cf545225b453501fa58d6.tar.bz2
Add try/catch in very rare scenario of html being returned instead of json. this 90% appears to be because of a timeout blip recently
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r--lib/sendgrid.js9
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';