title: Need better Node.js http.get request error handling
body: <p>I use following <code>http.get()</code> call to call a local endpoint:</p>
  
  <pre><code>http.get({
      host: 'localhost',
      port: 80,
      path: '/service/info?id=' + id
  }, function(response) {
              console.log(response);
      response.setEncoding('utf8');
      var data = "";
  
      response.on('data', function(chunk) {
          data += chunk;
      });
  
      response.on('end', function() {
          if(data.length &gt; 0) {
              try {
                  var data_object = JSON.parse(data);
              } catch(e) {
                  return;
              }
          }
      });
  }).on("error", function (){console.log("GET request error")});
  </code></pre>
  
  <p>However, if I send a malformed request, which would trigger a HTTP 400, the request is synthetically incorrect etc, even though the <code>response.statusCode</code> in <code>function(response)</code> is 400, it would end up to the <code>catch() response.on('end', function() {}</code> instead of emitting the error event on <code>http.get()</code>, I wonder why that's the case and how i can handle HTTP 400 response as an error on node.js. </p>
  
  <p>If it gets to <code>catch(e)</code>, it waits a long time till it responses anything to the client, which is also weird. I want the server to respond to the client that it hits a 400 as soon as possible. </p>