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.
This commit is contained in:
cloudmu
2016-09-05 14:33:31 -04:00
committed by Dan Abramov
parent f4d9d8dc9a
commit 29107ca29b

View File

@@ -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 + ').'
);
}
}