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. (facebook#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 George Czabania committed Sep 7, 2016
1 parent 1a2b61c commit bb0fbd9
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 bb0fbd9

Please sign in to comment.