andris9/Nodemailer — pull request #177 by MrSwitch (2013-07-25 07:19:24+00:00)
Title: Fixing Amazon SES, fatal error caused by bad connection

Hi Andris, I found a breaking bug and have a fix for it.

Bad connections cause a Fatal Error. And an uncaught error is thrown.

$ node test.js

events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)

Its actually a problem with `http.request()` made without a `req.on('error', handler)`. You can demo this by turning your internet connection off and running this code below (toggle the comment to see the fix).

// TURN OFF YOUR INTERNET CONNECTION TO TEST
var https = require('https');
try{

var req = https.request("https://google.com", function(){
console.log(arguments);
})
// UNCOMMENT THIS NEXT LINE TO FIX
// req.on('error', function(e) { console.log('problem with request: ' + e.message); });
}
catch(e){
console.log("Doesn't get caught");
}

Please merge my changes below. :)

Great project, thankyou.