Error handling on proxy error
What is the graceful way to handle proxy errors? Currently what happens if the server that should be proxied to fails, is that the application crashes with a:
.../node_modules/http-server/node_modules/http-proxy/lib/http-proxy/index.js:119
throw err;
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
The proxy object is not available. So I can not add an error handler. Something like the following would be very usefull:
if (typeof options.proxy === 'string') {
var proxy = httpProxy.createProxyServer({});
before.push(function (req, res) {
proxy.web(req, res, {
target: options.proxy,
changeOrigin: true
});
});
// NEW CODE HERE
if (options.proxyErrorHandler) {
proxy.on('error', options.proxyErrorHandler);
}
// END NEW CODE HERE
}
This is just an idea. But custom handling of errors in the proxy would be more useful to me, then an exception. :)
+1 ! a switch on cli command too !
I also met this error when my target server was starting and not yet ready to be used.
When ECONNREFUSED happens, instead of killing the http-server process, it is possible to simply return "503 Service Unavailable" to the client, keeping the http-server service alive?
Or at least, can be helpful to provide an option to disable this default behavior (exit process), returning 503 http code instead.
Any update on this? I have a similar issue (already posted here http://stackoverflow.com/questions/38795695/http-proxy-handling-econnrefused-and-econnreset before I found this).
Need this too. Any updates?
Any updates?