-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Specific error for timeouts #1331
Comments
Guys, any progress with this issue? |
rowanmanning
added a commit
to rowanmanning/node-http-proxy
that referenced
this issue
Oct 7, 2023
When using `proxyTimeout` it's very difficult to tell the difference between a regular socket hangup and a timeout because, in both cases, an `ECONNRESET` error is thrown. Ideally we should be able to identify when a proxy request has failed because it took too long, this would allow us to do things like send appropriate `504` status code. Suddenly throwing a different error would probably be considered a breaking change because it's possible that users of http-proxy are relying on the `ECONNRESET` error. I decided to add the custom timeout error behind a new option for now so that people can opt into using it. If you set this option: ```js var proxy = httpProxy.createProxyServer({ target: 'http://example.com', proxyTimeout: 100, proxyTimeoutCustomError: true }); ``` Then the error that gets thrown will have a message of `"The proxy request timed out"` and a code of `ETIMEDOUT` to match Node.js: https://nodejs.org/api/errors.html#common-system-errors This allows for custom error handling code like this: ```js proxy.on('error', function(err, req, res) { if (err.code === 'ETIMEDOUT') { res.writeHead(504); } else { res.writeHead(503); } // ... }); ``` Resolves http-party#1331.
@pablote and @Doc999tor I have a fix for this in #1650 however it may not be merged or may take some time to get merged based on the activity in this repo. I found a temporary solution which works for me: instead of setting the proxy.on('proxyReq', (proxyReq) => {
proxyReq.setTimeout(1000, () => {
const timeoutError = new Error('The proxy request timed out');
timeoutError.code = 'ETIMEDOUT';
proxyReq.destroy(timeoutError);
});
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm currently proxying requests like this:
If the upstream server takes too long, the callback is run with the following error:
Would it make sense to get a timeout specific error? so I can, if I chose to do so, return a specific timeout error like 504?
The text was updated successfully, but these errors were encountered: