Commit e1c41d06 authored by indexzero's avatar indexzero

[fix] Add guards to every throw-able res.end call

parent de4a6fe8
...@@ -178,7 +178,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { ...@@ -178,7 +178,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
} }
} }
res.end(); try { res.end() }
catch (ex) { console.error("res.end error: %s", ex.message) }
} }
// //
...@@ -209,7 +210,9 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { ...@@ -209,7 +210,9 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
// If `response.statusCode === 304`: No 'data' event and no 'end' // If `response.statusCode === 304`: No 'data' event and no 'end'
if (response.statusCode === 304) { if (response.statusCode === 304) {
return res.end(); try { res.end() }
catch (ex) { console.error("res.end error: %s", ex.message) }
return;
} }
// //
...@@ -223,9 +226,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { ...@@ -223,9 +226,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
try { try {
res.write(chunk); res.write(chunk);
} }
catch (er) { catch (ex) {
console.error("res.write error: %s", ex.message);
try { res.end() } try { res.end() }
catch (er) {} catch (ex) { console.error("res.write error: %s", ex.message) }
} }
} }
}); });
...@@ -240,8 +244,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { ...@@ -240,8 +244,10 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
response.on('end', function () { response.on('end', function () {
if (!errState) { if (!errState) {
reverseProxy.removeListener('error', proxyError); reverseProxy.removeListener('error', proxyError);
res.end();
try { res.end() }
catch (ex) { console.error("res.end error: %s", ex.message) }
// Emit the `end` event now that we have completed proxying // Emit the `end` event now that we have completed proxying
self.emit('end', req, res); self.emit('end', req, res);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment