You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document error handling in http2 client connect example #16345
Socket errors are actually emitted on socketError. So you would need to do client.on('socketError', (err) => console.log(err)); — I just double checked and it does log an ECONNREFUSED error.
changed the title [-]No exception thrown on http2 client connect failure[/-][+]Document error handling in http2 client connect example[/+]on Oct 21, 2017
Thanks, that worked! I updated the issue title to suggest updating the example code for client usage to reflect handling error and socketError.
As general feedback: I spent a while reading the http2 documentation, and to me it wasn't clear which methods apply to client usage vs server usage. The impression I'm starting to come to is that the http2 API is much more "symmetric" than the http API, in that lots of the events apply to both sides. Is that accurate? If so, the documentation might benefit from explaining this up front, and/or documenting for each event whether it can be thrown by clients or servers.
I would say that's correct, yes — both the client and the server use the same basic building blocks in Http2Session & Http2Stream. The session is almost identical between client & server. There are a few more differences for the stream which you can see here:
In general, we are VERY happy to accept PRs that improve the docs. If you would like to add an example illustrating error handling or expand the existing example, that would be amazing!
Another bit of clarification: Is the compatibility API intended to include client-side code? I tried to port some existing code that used the https module, but it failed calling req.pipe(), because there was no pipe method available.
The compatibility layer is strictly server side at the moment. For the client-side, I don't know if there's any plan to make it fully h1 compatible but — as far as I understand — we at the very least want to add something similar to the h1 Agent model.
Activity
jasnell commentedon Oct 20, 2017
that won't throw. Try adding a
client.on('error', ...)handlerjsha commentedon Oct 21, 2017
jasnell commentedon Oct 21, 2017
No. The underlying code is specifically designed to handle connection errors asynchronously. Attaching the handler after should work just fine
jsha commentedon Oct 21, 2017
I added a
client.on('error', ...), but it doesn't appear to fire:Output:
apapirovski commentedon Oct 21, 2017
Socket errors are actually emitted on
socketError. So you would need to doclient.on('socketError', (err) => console.log(err));— I just double checked and it does log an ECONNREFUSED error.Here's the documentation for it: https://nodejs.org/dist/latest-v8.x/docs/api/http2.html#http2_event_socketerror
jasnell commentedon Oct 21, 2017
Ha! Sigh that's right. Thank you for the correction @apapirovski!
[-]No exception thrown on http2 client connect failure[/-][+]Document error handling in http2 client connect example[/+]jsha commentedon Oct 21, 2017
Thanks, that worked! I updated the issue title to suggest updating the example code for client usage to reflect handling
errorandsocketError.As general feedback: I spent a while reading the http2 documentation, and to me it wasn't clear which methods apply to client usage vs server usage. The impression I'm starting to come to is that the http2 API is much more "symmetric" than the http API, in that lots of the events apply to both sides. Is that accurate? If so, the documentation might benefit from explaining this up front, and/or documenting for each event whether it can be thrown by clients or servers.
Thanks,
Jacob
apapirovski commentedon Oct 21, 2017
I would say that's correct, yes — both the client and the server use the same basic building blocks in Http2Session & Http2Stream. The session is almost identical between client & server. There are a few more differences for the stream which you can see here:
https://nodejs.org/dist/latest-v8.x/docs/api/http2.html#http2_class_clienthttp2stream
https://nodejs.org/dist/latest-v8.x/docs/api/http2.html#http2_class_serverhttp2stream
In general, we are VERY happy to accept PRs that improve the docs. If you would like to add an example illustrating error handling or expand the existing example, that would be amazing!
jsha commentedon Oct 21, 2017
Done: #16366.
Another bit of clarification: Is the compatibility API intended to include client-side code? I tried to port some existing code that used the
httpsmodule, but it failed callingreq.pipe(), because there was no pipe method available.apapirovski commentedon Oct 21, 2017
The compatibility layer is strictly server side at the moment. For the client-side, I don't know if there's any plan to make it fully h1 compatible but — as far as I understand — we at the very least want to add something similar to the h1 Agent model.
I'm surprised
pipedidn't work though. @ronag did a lot of work with http2 when buildingnode-http2-proxyand I'm reasonably certain that's usingpipea bunch. See the source here https://github.com/nxtedition/node-http2-proxy/blob/master/index.jsdoc: improve http2 documentation
doc: improve http2 documentation
doc: improve http2 documentation
doc: improve http2 documentation
doc: improve http2 documentation
doc: improve http2 documentation