Skip to content

Commit

Permalink
[api] Manual merge of #46: add custom proxyError event and enable p…
Browse files Browse the repository at this point in the history
…roduction error handling.
  • Loading branch information
indexzero committed May 19, 2011
1 parent bd45216 commit 652cca3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/node-http-proxy.js
Expand Up @@ -370,10 +370,28 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
//
function proxyError(err) {
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' });

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();
Expand Down

0 comments on commit 652cca3

Please sign in to comment.