hisco / http2-client

Transparently make http request to both http1 / http2 server.
https://www.npmjs.com/package/http2-client
MIT License
33 stars 14 forks source link

Network errors are not properly propagated #27

Closed stefan-guggisberg closed 3 years ago

stefan-guggisberg commented 4 years ago

Builtin http.request reports a network error by emitting an 'error' event on the returned http.ClientRequest:

const http = require('http');

const req = http.request('http://localhost:54321');
req.on('error', (err) => console.log(err));  // => Error: connect ECONNREFUSED 127.0.0.1:54321
req.end();

http2-client however doesn't emit the 'error' event in the same scenario:

const http = require('http2-client');

const req = http.request('http://localhost:54321');
req.on('error', (err) => console.log(err));  // => never get here...
req.end();  // => process exits

console output:

events.js:288
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:54321
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 54321
}
hisco commented 3 years ago

Published 1.3.5