From 29107ca29b0b85b16c87efc363f2908a2d8d915b Mon Sep 17 00:00:00 2001
From: cloudmu <cloudmu@users.noreply.github.com>
Date: Mon, 5 Sep 2016 14:33:31 -0400
Subject: [PATCH] Send proper error response in custom onError handler for
 httpProxyMiddleware. (#588)

* Change http-proxy-middleware logLevel from silent to error

* provide onError handler for httpProxyMiddleware

* Send proper error reponse upon proxy error.
---
 scripts/start.js | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/start.js b/scripts/start.js
index a0b01545b..a1d984017 100644
--- a/scripts/start.js
+++ b/scripts/start.js
@@ -184,6 +184,15 @@ function onProxyError(proxy) {
       chalk.cyan(err.code) + ').'
     );
     console.log();
+
+    // And immediately send the proper error response to the client.
+    // Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
+    if (res.writeHead && !res.headersSent) {
+        res.writeHead(500);
+    }
+    res.end('Proxy error: Could not proxy request ' + req.url + ' from ' + 
+      host + ' to ' + proxy + ' (' + err.code + ').'
+    );
   }
 }
 
-- 
GitLab