Closed stefan-guggisberg closed 3 years ago
Builtin http.request reports a network error by emitting an 'error' event on the returned http.ClientRequest:
http.request
'error'
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:
http2-client
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 }
Published 1.3.5
Builtin
http.request
reports a network error by emitting an'error'
event on the returnedhttp.ClientRequest
:http2-client
however doesn't emit the'error'
event in the same scenario:console output: