http-proxy-middleware icon indicating copy to clipboard operation
http-proxy-middleware copied to clipboard

fix(websocket): handle errors in handleUpgrade

Open nwalters512 opened this issue 3 years ago • 5 comments
trafficstars

Description

When there is an error from user-provided code (pathFilter, rewritePath, or router), that error is now handled and exposed to the user via proxy.emit('error', ...).

error-response-plugin was also updated to handle the fact that it might receive a socket. If it does, it will call socket.destroy().

Motivation and Context

See #822 for a description of the issue being fixed. This PR closes #822.

How has this been tested?

I added a new test case. It fails on master, and works correctly with my new changes.

Types of changes

I'm split on whether or not this should be considered a breaking change. Folks could have written code assuming that the error handler would always get a Response as the third argument, whereas now it would get a Socket. That said, the TypeScript types from http-proxy do reflect that that could be a Socket, so it shouldn't come as too much of a surprise.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.

nwalters512 avatar Sep 05 '22 00:09 nwalters512

@chimurai 👋 can I do anything to help this along?

nwalters512 avatar Sep 11 '22 18:09 nwalters512

Sorry for the late reply. I'll need some time to review 🙏

chimurai avatar Sep 15 '22 20:09 chimurai

@chimurai thanks!

nwalters512 avatar Sep 26 '22 21:09 nwalters512

@chimurai is there any chance you'd be able to review soon? If so, I'll resolve the merge conflicts with master.

nwalters512 avatar Feb 15 '24 19:02 nwalters512