-
Notifications
You must be signed in to change notification settings - Fork 124
fix: handle err on both start and stop echo-server #569
Conversation
You need to register for the |
promisifing events is tricky business, do you have any example of a use-case where the error coming from |
My point is there will be no error passed to the callback passed to When you start a server you'll either get a |
humm right i didn't got that the callback is just a listener to the This makes more sense now :) plus as we are only wrapping it in a server.start = (opts) => new Promise((resolve, reject) => {
server.once('error', reject)
server.listen(Object.assign({ port: defaultPort, host: '127.0.0.1' }, opts), () => {
server.removeListener('error', reject)
resolve()
})
}) |
@achingbrain , can you give me a second review here, please? |
src/utils/echo-http-server.js
Outdated
server.stop = () => new Promise((resolve) => server.close(resolve)) | ||
server.stop = () => new Promise((resolve, reject) => { | ||
server.once('error', reject) | ||
server.close(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the callback can be called with an Error if the server was not open
https://github.com/nodejs/node/blob/9cfb3841785cd658bb13369ed642247e089a5533/lib/net.js#L1519
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that on docs but I thought server.once('error', reject)
would call its callback on any error (including the [ERR_SERVER_NOT_RUNNING]
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, do we really need to listen error
event in this case?
echo-server
was not handling properly error on bothstart()
andstop()
methods.@achingbrain suggested on #565 's review:
I think we just want to check
server.listen()
andserver.close()
related errors. For this reason, my suggestion is: