7

Below is the code for my Node.js HTTP response requester.

Once I use a website that I explicitly know does not exist, the error message would notify me the error: getaddrinfo ENOENT

I want to know more about this error. What spawns it? What's the detail of the error? Would 404' spawn it?

var hostNames = ['www.pageefef.com'];

for (i; i < hostNames.length; i++){

    var options = {
            host: hostNames[i],
            path: '/'
    };

  (function (i){
    http.get(options, function(res) {

      var obj = {};
      obj.url = hostNames[i];
      obj.statusCode = res.statusCode;
      // obj.headers = res.headers;

      console.log(JSON.stringify(obj, null, 4));
    }).on('error',function(e){
      console.log("Error: " + hostNames[i] + "\n" + e.message);
    });
  })(i);
};
theGreenCabbage
  • 5,197
  • 19
  • 79
  • 169

1 Answers1

8

You can do this to get more details about error.

.on('error',function(e){
   console.log("Error: " + hostNames[i] + "\n" + e.message); 
   console.log( e.stack );
});

If you give a non-existent url then above code returns :

getaddrinfo ENOTFOUND
Error: getaddrinfo ENOTFOUND
    at errnoException (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)

The error is thrown from http.ClientRequest class by http.request(). No a 404 will not generate this error. Error 404 means that the client was able to communicate with the server, but the server could not find what was requested. This error means Domain Name System failed to find the address (dns.js is for NAPTR queries).

user568109
  • 47,225
  • 17
  • 99
  • 123
  • 1
    This detailed error report was what I was looking for, but I feel like a dog that's caught a car, and don't know what to do with it. Once I have this error, what should I do? Because there is a variety of them, should I analyze it, or just remove these defunct URLs from my list of scrapings? – theGreenCabbage Mar 20 '13 at 16:14
  • error means that url is inaccessible, so check with your ISP if it is not blocked. Otherwise you should remove the urls. – user568109 Mar 20 '13 at 16:20