title: http get NodeJS how to get error status code?
body: <p>OK, I must be dense since I cannot find anywhere how to get the error status codes when using Node.JS <code>http.get</code> or <code>http.request</code>. </p>
  
  <p><strong>My code:</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>var deferred = $q.defer();
  var req = https.get(options, function(response) {
    var str = '';
    response.on('data', function(chunk) {
      str += chunk;
    });
    response.on('end', function() {
      console.log("[evfService] Got user info: " + str);
      deferred.resolve(str);
    });
  });
  
  req.on('error', function(e) {
    deferred.reject(e);
  });
  </code></pre>
  
  
  
  <p>In that "req.on" bit, what I want is the http status code (i.e. 401, 403, etc.). What I get is a semi-useless error object that does not give me the code or any reference to the response object. </p>
  
  <p>I have tried intercepting in the function(response) callback, but when there is a 404, it never gets called.</p>
  
  <p>Thanks!</p>