@@ -108,6 +108,10 @@ export type ClientOptions = Partial<ChannelOptions> & {
108
108
callInvocationTransformer ?: CallInvocationTransformer ;
109
109
} ;
110
110
111
+ function getErrorStackString ( error : Error ) : string {
112
+ return error . stack ! . split ( '\n' ) . slice ( 1 ) . join ( '\n' ) ;
113
+ }
114
+
111
115
/**
112
116
* A generic gRPC client. Primarily useful as a base class for all generated
113
117
* clients.
@@ -321,7 +325,7 @@ export class Client {
321
325
}
322
326
let responseMessage : ResponseType | null = null ;
323
327
let receivedStatus = false ;
324
- const callerStack = ( new Error ( ) . stack ! ) . split ( '\n' ) . slice ( 1 ) . join ( '\n' ) ;
328
+ const callerStackError = new Error ( ) ;
325
329
call . start ( callProperties . metadata , {
326
330
onReceiveMetadata : ( metadata ) => {
327
331
emitter . emit ( 'metadata' , metadata ) ;
@@ -340,6 +344,7 @@ export class Client {
340
344
receivedStatus = true ;
341
345
if ( status . code === Status . OK ) {
342
346
if ( responseMessage === null ) {
347
+ const callerStack = getErrorStackString ( callerStackError ) ;
343
348
callProperties . callback ! ( callErrorFromStatus ( {
344
349
code : Status . INTERNAL ,
345
350
details : 'No message received' ,
@@ -349,6 +354,7 @@ export class Client {
349
354
callProperties . callback ! ( null , responseMessage ) ;
350
355
}
351
356
} else {
357
+ const callerStack = getErrorStackString ( callerStackError ) ;
352
358
callProperties . callback ! ( callErrorFromStatus ( status , callerStack ) ) ;
353
359
}
354
360
emitter . emit ( 'status' , status ) ;
@@ -447,7 +453,7 @@ export class Client {
447
453
}
448
454
let responseMessage : ResponseType | null = null ;
449
455
let receivedStatus = false ;
450
- const callerStack = ( new Error ( ) . stack ! ) . split ( '\n' ) . slice ( 1 ) . join ( '\n' ) ;
456
+ const callerStackError = new Error ( ) ;
451
457
call . start ( callProperties . metadata , {
452
458
onReceiveMetadata : ( metadata ) => {
453
459
emitter . emit ( 'metadata' , metadata ) ;
@@ -466,6 +472,7 @@ export class Client {
466
472
receivedStatus = true ;
467
473
if ( status . code === Status . OK ) {
468
474
if ( responseMessage === null ) {
475
+ const callerStack = getErrorStackString ( callerStackError ) ;
469
476
callProperties . callback ! ( callErrorFromStatus ( {
470
477
code : Status . INTERNAL ,
471
478
details : 'No message received' ,
@@ -475,6 +482,7 @@ export class Client {
475
482
callProperties . callback ! ( null , responseMessage ) ;
476
483
}
477
484
} else {
485
+ const callerStack = getErrorStackString ( callerStackError ) ;
478
486
callProperties . callback ! ( callErrorFromStatus ( status , callerStack ) ) ;
479
487
}
480
488
emitter . emit ( 'status' , status ) ;
@@ -577,7 +585,7 @@ export class Client {
577
585
call . setCredentials ( callProperties . callOptions . credentials ) ;
578
586
}
579
587
let receivedStatus = false ;
580
- const callerStack = ( new Error ( ) . stack ! ) . split ( '\n' ) . slice ( 1 ) . join ( '\n' ) ;
588
+ const callerStackError = new Error ( ) ;
581
589
call . start ( callProperties . metadata , {
582
590
onReceiveMetadata ( metadata : Metadata ) {
583
591
stream . emit ( 'metadata' , metadata ) ;
@@ -593,6 +601,7 @@ export class Client {
593
601
receivedStatus = true ;
594
602
stream . push ( null ) ;
595
603
if ( status . code !== Status . OK ) {
604
+ const callerStack = getErrorStackString ( callerStackError ) ;
596
605
stream . emit ( 'error' , callErrorFromStatus ( status , callerStack ) ) ;
597
606
}
598
607
stream . emit ( 'status' , status ) ;
@@ -675,7 +684,7 @@ export class Client {
675
684
call . setCredentials ( callProperties . callOptions . credentials ) ;
676
685
}
677
686
let receivedStatus = false ;
678
- const callerStack = ( new Error ( ) . stack ! ) . split ( '\n' ) . slice ( 1 ) . join ( '\n' ) ;
687
+ const callerStackError = new Error ( ) ;
679
688
call . start ( callProperties . metadata , {
680
689
onReceiveMetadata ( metadata : Metadata ) {
681
690
stream . emit ( 'metadata' , metadata ) ;
@@ -690,6 +699,7 @@ export class Client {
690
699
receivedStatus = true ;
691
700
stream . push ( null ) ;
692
701
if ( status . code !== Status . OK ) {
702
+ const callerStack = getErrorStackString ( callerStackError ) ;
693
703
stream . emit ( 'error' , callErrorFromStatus ( status , callerStack ) ) ;
694
704
}
695
705
stream . emit ( 'status' , status ) ;
0 commit comments