http-server icon indicating copy to clipboard operation
http-server copied to clipboard

Error handling on proxy error

Open ducklord opened this issue 11 years ago • 5 comments

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. :)

ducklord avatar Oct 14 '15 11:10 ducklord

+1 ! a switch on cli command too !

aleclofabbro avatar Nov 26 '15 14:11 aleclofabbro

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.

jraduget avatar May 11 '16 16:05 jraduget

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).

ScriptPup avatar Aug 05 '16 18:08 ScriptPup

Need this too. Any updates?

AndersDJohnson avatar Jul 25 '17 02:07 AndersDJohnson

Any updates?

killmenot avatar Feb 27 '18 08:02 killmenot