mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-20 12:46:30 +08:00
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:
@@ -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 + ').'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user