question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error handling on proxy error

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

2reactions
jradugetcommented, May 11, 2016

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.

2reactions
aleclofabbrocommented, Nov 26, 2015

+1 ! a switch on cli command too !

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Solve Proxy Error Codes - The Ultimate Guide! - NetNut
A proxy error is an HTTP error status that you will receive as a response when a request sent to the web server...
Read more >
Proxy Services: Error Handlers - Oracle Help Center
Since an error handler is another pipeline, it is configured like any other pipeline. For example, the Publish action may be used to...
Read more >
How to Solve Proxy Error Codes - Infatica
Errors make scraping unbearably difficult or even impossible to execute. In this article, we will take a look at all HTTP error codes...
Read more >
Proxy error handling · Issue #138 · microsoft/reverse ... - GitHub
Describe the bug. The proxy should catch exceptions from the HttpProxy and convert them to 503s or other statuses as appropriate.
Read more >
Error Handling via Try & Catch Proxy in Javascript - Medium
1.First, we define proxy function that takes an argument, which is the class that we are going to wrap its methods. · 2....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found