From 22fd93e3f58d58f7477d0d71cd709fdd4ed1710c Mon Sep 17 00:00:00 2001 From: "Jeremy R. Fishman" Date: Mon, 23 May 2016 17:28:42 -0700 Subject: [PATCH] handle https client errors --- mailgun.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mailgun.js b/mailgun.js index 3292d61..6ef1def 100755 --- a/mailgun.js +++ b/mailgun.js @@ -140,6 +140,10 @@ Mailgun.prototype.sendText = function(sender, recipients, subject, text) { if (callback) callback(res.statusCode != 201 ? new Error(res.statusCode) : undefined); }); + req.on('error', function(err) { + if (callback) callback(err); + }); + // Wrap up the request by sending the body, which contains the // actual email data we want to send. req.end(body); @@ -205,6 +209,10 @@ Mailgun.prototype.sendRaw = function(sender, recipients, rawBody) { if (callback) callback(res.statusCode != 201 ? new Error(res.statusCode) : undefined); }); + req.on('error', function(err) { + if (callback) callback(err); + }); + // Wrap up the request by sending the message, which contains the // actual email data we want to send. req.end(message);