-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Unhandled error in http.request, even with provided error event listener: getaddrinfo ENOTFOUND #8819
Comments
@jedmao what version of node are you using? This isn't reproducing for me on 0.11.14. |
@cjihrig the current stable version v0.10.33 |
@jedmao, tested on v0.10.32 and v0.10.33, works as expected, what OS are you using? looks like an synchronous request |
Try running just the first 2 lines of code and see the error. var http = require('http');
var req = http.request('http://foo.bar.baz/qux'); Or type those 2 lines in a Node shell and see what I'm talking about. You shouldn't get an error here, just because you haven't yet attached an error handler, right? It should wait for Tell me if this is somehow by design. |
I would say this is expected behavior, but could be clearer in the documentation. The var http = require('http');
var req = http.request('http://foo.bar.baz/qux');
process.nextTick(function() {
req.on('error', function(err) {
console.error(err.message);
});
}); I still have not been able to reproduce your original issue (not to say that it isn't possible). And, as @a0viedo pointed out, the two code samples translate into the same thing. |
Closing as by design. |
I'm calling
http.request()
and attaching an error event listener like so:And I get the following error:
Wrapping the request in a
try...catch
block still throws an unhandled error. My only work-around is to chain the event listener, like so:Which handles the error gracefully and as expected:
I'm not quite sure how this should make any difference, but it does.
This should work without chaining, no?
Similar issues: #4846 #7729 #8647
The text was updated successfully, but these errors were encountered: