when I'm trying to use the http
module to access nonexistent host, like this:
requestToRemote = http.createClient(80, 'fjasdfhasdkfj.vvvxcz').request(
method,
path,
headers
);
But I get the following error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: getaddrinfo ENOENT
at errnoException (dns.js:31:11)
at Object.onanswer [as oncomplete] (dns.js:140:16)
I'd like to catch this error, so I've tried try/catch and setting the error listeners of a bunch of request properties, but none of if worked. How can I catch the error?
The http module is available natively with Node. js; there is no additional installation required. The data is initially converted into a string using the stringify function. The HTTP options specify the headers, destination address, and request method type.
The stack trace is useful while debugging code as it shows the exact point that has caused an error. Errors in Node. js can be classified into four broad categories: Standard JavaScript Errors.
Looks like the error is thrown from http.Client
, not the request. How about something like:
var site = http.createClient(80, host);
site.on('error', function(err) {
sys.debug('unable to connect to ' + host);
});
var requestToRemote = site.request(...);
FYI, http.createClient
has been deprecated -- the following should work using the get convenience method:
http.get({host: host}, function(res) {
...
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With