mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[api] Manual merge of #46: add custom proxyError event and enable production error handling.
This commit is contained in:
parent
bd45216bc9
commit
652cca37ea
@ -370,10 +370,28 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
|
|||||||
//
|
//
|
||||||
function proxyError(err) {
|
function proxyError(err) {
|
||||||
errState = true;
|
errState = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Emit an `error` event, allowing the application to use custom
|
||||||
|
// error handling. The error handler should end the response.
|
||||||
|
//
|
||||||
|
if (self.emit('proxyError', err, req, res)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
res.writeHead(500, { 'Content-Type': 'text/plain' });
|
||||||
|
|
||||||
if (req.method !== 'HEAD') {
|
if (req.method !== 'HEAD') {
|
||||||
res.write('An error has occurred: ' + JSON.stringify(err));
|
//
|
||||||
|
// This NODE_ENV=production behavior is mimics Express and
|
||||||
|
// Connect.
|
||||||
|
//
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
res.write('Internal Server Error');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.write('An error has occurred: ' + JSON.stringify(err));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user