@@ -568,7 +568,7 @@ export class Http2ServerCallStream<
568
568
this . stream . on ( 'end' , onEnd ) ;
569
569
this . stream . on ( 'error' , onEnd ) ;
570
570
571
- async function onData ( chunk : Buffer ) {
571
+ function onData ( chunk : Buffer ) {
572
572
receivedLength += chunk . byteLength ;
573
573
574
574
if ( limit !== - 1 && receivedLength > limit ) {
@@ -586,7 +586,7 @@ export class Http2ServerCallStream<
586
586
body . push ( chunk ) ;
587
587
}
588
588
589
- async function onEnd ( err ?: Error ) {
589
+ function onEnd ( err ?: Error ) {
590
590
stream . removeListener ( 'data' , onData ) ;
591
591
stream . removeListener ( 'end' , onEnd ) ;
592
592
stream . removeListener ( 'error' , onEnd ) ;
@@ -615,13 +615,19 @@ export class Http2ServerCallStream<
615
615
) ;
616
616
617
617
if ( Buffer . isBuffer ( decompressedMessage ) ) {
618
- call . safeDeserializeMessage ( decompressedMessage , resolve , reject ) ;
618
+ call
619
+ . deserializeMessageWithInternalError ( decompressedMessage )
620
+ . then ( resolve )
621
+ . catch ( reject ) ;
619
622
return ;
620
623
}
621
624
622
625
decompressedMessage . then (
623
626
decompressed =>
624
- call . safeDeserializeMessage ( decompressed , resolve , reject ) ,
627
+ call
628
+ . deserializeMessageWithInternalError ( decompressed )
629
+ . then ( resolve )
630
+ . catch ( reject ) ,
625
631
( err : any ) =>
626
632
reject (
627
633
err . code
@@ -636,20 +642,14 @@ export class Http2ServerCallStream<
636
642
} ) ;
637
643
}
638
644
639
- private safeDeserializeMessage (
640
- buffer : Buffer ,
641
- resolve : (
642
- value : void | RequestType | PromiseLike < void | RequestType >
643
- ) => void ,
644
- reject : ( reason : any ) => void
645
- ) {
645
+ private async deserializeMessageWithInternalError ( buffer : Buffer ) {
646
646
try {
647
- resolve ( this . deserializeMessage ( buffer ) ) ;
647
+ return this . deserializeMessage ( buffer ) ;
648
648
} catch ( err ) {
649
- reject ( {
649
+ throw {
650
650
details : getErrorMessage ( err ) ,
651
651
code : Status . INTERNAL ,
652
- } ) ;
652
+ } ;
653
653
}
654
654
}
655
655
0 commit comments