Skip to content

Commit 29107ca

Browse files
cloudmugaearon
authored andcommitted
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.
1 parent f4d9d8d commit 29107ca

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

scripts/start.js

+9
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ function onProxyError(proxy) {
184184
chalk.cyan(err.code) + ').'
185185
);
186186
console.log();
187+
188+
// And immediately send the proper error response to the client.
189+
// Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
190+
if (res.writeHead && !res.headersSent) {
191+
res.writeHead(500);
192+
}
193+
res.end('Proxy error: Could not proxy request ' + req.url + ' from ' +
194+
host + ' to ' + proxy + ' (' + err.code + ').'
195+
);
187196
}
188197
}
189198

0 commit comments

Comments
 (0)