New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Re-add support for clientError listeners #1897
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure about this. So it is an event emitter, so obviously two handlers is technically valid, but the use case here is almost certainly to be sending a response in some cases, which shifts the burden onto each handler to make sure it properly checks before sending the response and closing the socket. If a user does this in multiple handlers they could get some pretty unexpected error results if they are not careful.
Could a better user experience from restify be to error or warn when they try to add a second handler?
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.
@wesleytodd, I agree generally. This is more of a contrived test rather than a valid usage example. I added this test to make sure that the proxying is done correctly / doesn't emit the proxied event multiple times if multiple listeners are added.
My goal with this change was to restore the ability to add a
clientError
listener after #1895 removed it, so am matching the original behavior here. I don't think folks would do this very often if at all. One actual use case might be to do the response in one handler and log in another. I'm not opposed to adding a warning but feels beyond the scope of this change.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.
cool, yeah makes sense. I just wanted to bring up this as I have thought before that sometimes these kind of api's from node core have foot guns, and I think frameworks are generally good places to shore up those gaps. I for sure don't think this one is a common issue worth spending much time on. So 👍 to the change!