restify / clients

HttpClient, StringClient, and JsonClient extracted from restify
MIT License
57 stars 34 forks source link

new: emit after event #179

Closed DonutEspresso closed 6 years ago

DonutEspresso commented 6 years ago

I thought this was going to be straight forward but it got messy much more quickly than I expected. This mostly had to do with a patchwork of how the request lifecycle was being handled. In short, this PR:

Because HttpClient consumes the streams directly, after doesn't really seem to make sense there. Thus, it's implemented in only StringClient and JSONClient. The tests aren't anywhere close to being complete - but wanted to get a sanity check first from the peanut gallery.

DonutEspresso commented 6 years ago

I also want to add that the implementations of the parse() method leave a bit to be desired - it mixes the lower level http errors along with parsing errors, and is quite difficult to reason about. I think it's worth addressing at some point but a bit outside of the scope of this PR, so I've kept the logic mostly intact.

DonutEspresso commented 6 years ago

Finished adding the complete suite of tests.

DonutEspresso commented 6 years ago

Thanks all, I tried to address all comments with the latest commits. Just to be sure, are we all aligned on HttpClient not emitting the after event? I think it makes sense to me but want to make sure I'm not missing anything.

DonutEspresso commented 6 years ago

Summarizing some offline conversations:

We'll support after even on the HttpClient, but errors cannot be as fully fleshed out as JSONClient/StringClient since the HttpClient does not do any response parsing. It's on userland to augment the existing error. If new errors are created in the callback (e.g., parsing errors), the only way after can get access to them is if it's tacked on via the request or response objects.

DonutEspresso commented 6 years ago

This PR is now ready for a final pass.

misterdjules commented 6 years ago

@DonutEspresso Latest changes look good to me! Thank you! 🙏

DonutEspresso commented 6 years ago

Thanks for the feedback all!