pgte/nock — pull request #206 by mdlavin (2014-07-02 14:50:30+00:00)
Title: Report request errors through the error event

This issue is very similar to #205 which I previously summitted a pull request for. This new pull request catches more cases where errors are thrown rather than emitting an error. Here is the justification for the change, for anybody who doesn't want to read the previous pull request:

The [documentation for http.request](http://nodejs.org/api/http.html#http_http_request_options_callback) says:

> If any error is encountered during the request (be that with DNS resolution, TCP level errors, or actual HTTP parse errors) an 'error' event is emitted on the returned request object.

I think that access to the host being blocked would fall into that situation and libraries designed to use the error event will not expect the error to be thrown. The AWS SDK is one such library, the one that caused me to find this problem.

Another example of the expectation of error reporting is in the [example code for the http.get](http://nodejs.org/api/http.html#http_http_get_options_callback) call:

```javascript
http.get("http://www.google.com/index.html", function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
```

With these changes, the testcases checking for errors now matches the example code from the http documentation.