Skip to content

Commit

Permalink
Send proper error response in custom onError handler for httpProxyMid…
Browse files Browse the repository at this point in the history
…dleware. (#588)

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

* provide onError handler for httpProxyMiddleware

* Send proper error reponse upon proxy error.
  • Loading branch information
cloudmu authored and gaearon committed Sep 5, 2016
1 parent f4d9d8d commit 29107ca
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ').'
);
}
}

Expand Down

0 comments on commit 29107ca

Please sign in to comment.