Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow sending a custom proxy timeout error
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.
- Loading branch information