Node-http-proxy: `proxy.web(...)` should provide some way to enable promisification

Created on 18 Jan 2019  路  1Comment  路  Source: http-party/node-http-proxy

I ran into an error tonight where I was calling proxy.web at the end of an express route handler and because it was asynchronous with no way to confirm success, I had to let it drop through the end of the handler. The problem is that, because it dropped through, when any error happened in the connection, it threw a process-killing error in the global scope, rather than within my defined try/catch block. If the function would in some way indicate success, then I could promisify it and await it, which would allow me to catch the error within my normal flow.

I see three main options:

  • Just update the function to return a promise instead of using the traditional callback technique
  • Update the callback signature to make the error optionally null, which would signal that the request was successful
  • Add an additional callback that is called on success

The first two would be considerably more modern, but of course, would break the current interface, meaning a major version bump. The last one would obviously work without a major bump, but would be more old school.... Let me know if you think there's merit to this.

Most helpful comment

Hello! I'm going to be working with the other maintainers to etch out what the next milestone will look like, and I absolutely agree this is most likely a must have. Thanks for your input :)

>All comments

Hello! I'm going to be working with the other maintainers to etch out what the next milestone will look like, and I absolutely agree this is most likely a must have. Thanks for your input :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robertjchristian picture robertjchristian  路  6Comments

mohammad-goldast picture mohammad-goldast  路  3Comments

sisyphsu picture sisyphsu  路  3Comments

catamphetamine picture catamphetamine  路  6Comments

jnjnljljjsw picture jnjnljljjsw  路  6Comments