@@ -404,8 +404,13 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
404
404
// then respond with `404` since we do not have a valid proxy target.
405
405
//
406
406
if ( ! location ) {
407
- res . writeHead ( 404 ) ;
408
- return res . end ( ) ;
407
+ try {
408
+ res . writeHead ( 404 ) ;
409
+ res . end ( ) ;
410
+ } catch ( er ) {
411
+ console . error ( "res.writeHead/res.end error: %s" , er . message ) ;
412
+ }
413
+ return ;
409
414
}
410
415
411
416
//
@@ -480,7 +485,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
480
485
}
481
486
}
482
487
483
- res . end ( ) ;
488
+ try {
489
+ res . end ( ) ;
490
+ } catch ( er ) {
491
+ console . error ( "res.end error: %s" , er . message ) ;
492
+ }
484
493
}
485
494
486
495
outgoing = {
@@ -508,7 +517,12 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
508
517
509
518
// `response.statusCode === 304`: No 'data' event and no 'end'
510
519
if ( response . statusCode === 304 ) {
511
- return res . end ( ) ;
520
+ try {
521
+ res . end ( ) ;
522
+ } catch ( er ) {
523
+ console . error ( "res.end error: %s" , er . message )
524
+ }
525
+ return ;
512
526
}
513
527
514
528
// For each data `chunk` received from the `reverseProxy`
@@ -520,9 +534,12 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
520
534
try {
521
535
res . write ( chunk ) ;
522
536
} catch ( er ) {
537
+ console . error ( "res.write error: %s" , er . message ) ;
523
538
try {
524
539
res . end ( ) ;
525
- } catch ( er ) { }
540
+ } catch ( er ) {
541
+ console . error ( "res.end error: %s" , er . message ) ;
542
+ }
526
543
}
527
544
}
528
545
} ) ;
@@ -535,7 +552,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
535
552
response . on ( 'end' , function ( ) {
536
553
if ( ! errState ) {
537
554
reverseProxy . removeListener ( 'error' , proxyError ) ;
538
- res . end ( ) ;
555
+ try {
556
+ res . end ( ) ;
557
+ } catch ( er ) {
558
+ console . error ( "res.end error: %s" , er . message ) ;
559
+ }
539
560
540
561
// Emit the `end` event now that we have completed proxying
541
562
self . emit ( 'end' , req , res ) ;
0 commit comments