diff --git a/lib/http.js b/lib/http.js index 7c6d753f..bb66b72b 100644 --- a/lib/http.js +++ b/lib/http.js @@ -702,7 +702,12 @@ function OutgoingResponse(stream) { this.stream = stream; this.statusCode = 200; this.sendDate = true; - + var self = this; + this.stream.on('error', function (error) { + self._log.error('Stream error: ' + error.toString()); + self.emit('error', error); + }); + this.stream.on('error', this.emit.bind(this, 'error')); this.stream.once('headers', this._onRequestHeaders.bind(this)); } OutgoingResponse.prototype = Object.create(OutgoingMessage.prototype, { constructor: { value: OutgoingResponse } }); @@ -970,6 +975,10 @@ Agent.prototype.request = function request(options, callback) { endpoint = new Endpoint(self._log, 'CLIENT', self._settings); endpoint.socket = httpsRequest.socket; endpoint.pipe(endpoint.socket).pipe(endpoint); + endpoint.on('error', function (error) { + self._log.error('Endpoint error: ' + error.toString()); + httpsRequest.emit('error', error); + }); } if (started) { // ** In the meantime, an other connection was made to the same host... @@ -1059,6 +1068,12 @@ OutgoingRequest.prototype._start = function _start(stream, options) { this.options = options; this._log = stream._log.child({ component: 'http' }); + + var self = this; + stream.on('error', function (error) { + self._log.error('Stream error: ' + error.toString()); + self.emit('error', error); + }); for (var key in options.headers) { this.setHeader(key, options.headers[key]); diff --git a/test/http.js b/test/http.js index efd0f393..6dcf12a9 100644 --- a/test/http.js +++ b/test/http.js @@ -186,14 +186,14 @@ describe('http.js', function() { } else { called = true; } - }, once: util.noop }; + }, once: util.noop, on: util.noop }; var response = new http2.OutgoingResponse(stream); response.writeHead(200); response.writeHead(404); }); it('field finished should be Boolean', function(){ - var stream = { _log: util.log, headers: function () {}, once: util.noop }; + var stream = { _log: util.log, headers: function () {}, once: util.noop, on: util.noop }; var response = new http2.OutgoingResponse(stream); expect(response.finished).to.be.a('Boolean'); });