@@ -68,6 +68,28 @@ function getNewCallNumber(): number {
68
68
return callNumber ;
69
69
}
70
70
71
+ const INAPPROPRIATE_CONTROL_PLANE_CODES : Status [ ] = [
72
+ Status . OK ,
73
+ Status . INVALID_ARGUMENT ,
74
+ Status . NOT_FOUND ,
75
+ Status . ALREADY_EXISTS ,
76
+ Status . FAILED_PRECONDITION ,
77
+ Status . ABORTED ,
78
+ Status . OUT_OF_RANGE ,
79
+ Status . DATA_LOSS
80
+ ]
81
+
82
+ function restrictControlPlaneStatusCode ( code : Status , details : string ) : { code : Status , details : string } {
83
+ if ( INAPPROPRIATE_CONTROL_PLANE_CODES . includes ( code ) ) {
84
+ return {
85
+ code : Status . INTERNAL ,
86
+ details : `Invalid status from control plane: ${ code } ${ Status [ code ] } ${ details } `
87
+ }
88
+ } else {
89
+ return { code, details} ;
90
+ }
91
+ }
92
+
71
93
/**
72
94
* An interface that represents a communication channel to a server specified
73
95
* by a given address.
@@ -320,7 +342,7 @@ export class ChannelImplementation implements Channel {
320
342
this . trace ( 'Name resolution failed with calls queued for config selection' ) ;
321
343
}
322
344
if ( this . configSelector === null ) {
323
- this . currentResolutionError = status ;
345
+ this . currentResolutionError = { ... restrictControlPlaneStatusCode ( status . code , status . details ) , metadata : status . metadata } ;
324
346
}
325
347
const localQueue = this . configSelectionQueue ;
326
348
this . configSelectionQueue = [ ] ;
@@ -534,10 +556,11 @@ export class ChannelImplementation implements Channel {
534
556
} ,
535
557
( error : Error & { code : number } ) => {
536
558
// We assume the error code isn't 0 (Status.OK)
537
- callStream . cancelWithStatus (
559
+ const { code , details } = restrictControlPlaneStatusCode (
538
560
typeof error . code === 'number' ? error . code : Status . UNKNOWN ,
539
561
`Getting metadata from plugin failed with error: ${ error . message } `
540
- ) ;
562
+ )
563
+ callStream . cancelWithStatus ( code , details ) ;
541
564
}
542
565
) ;
543
566
}
@@ -549,17 +572,13 @@ export class ChannelImplementation implements Channel {
549
572
if ( callMetadata . getOptions ( ) . waitForReady ) {
550
573
this . pushPick ( callStream , callMetadata , callConfig , dynamicFilters ) ;
551
574
} else {
552
- callStream . cancelWithStatus (
553
- pickResult . status ! . code ,
554
- pickResult . status ! . details
555
- ) ;
575
+ const { code, details} = restrictControlPlaneStatusCode ( pickResult . status ! . code , pickResult . status ! . details ) ;
576
+ callStream . cancelWithStatus ( code , details ) ;
556
577
}
557
578
break ;
558
579
case PickResultType . DROP :
559
- callStream . cancelWithStatus (
560
- pickResult . status ! . code ,
561
- pickResult . status ! . details
562
- ) ;
580
+ const { code, details} = restrictControlPlaneStatusCode ( pickResult . status ! . code , pickResult . status ! . details ) ;
581
+ callStream . cancelWithStatus ( code , details ) ;
563
582
break ;
564
583
default :
565
584
throw new Error (
@@ -668,10 +687,8 @@ export class ChannelImplementation implements Channel {
668
687
this . tryPick ( stream , metadata , callConfig , [ ] ) ;
669
688
}
670
689
} else {
671
- stream . cancelWithStatus (
672
- callConfig . status ,
673
- 'Failed to route call to method ' + stream . getMethod ( )
674
- ) ;
690
+ const { code, details} = restrictControlPlaneStatusCode ( callConfig . status , 'Failed to route call to method ' + stream . getMethod ( ) ) ;
691
+ stream . cancelWithStatus ( code , details ) ;
675
692
}
676
693
}
677
694
}
0 commit comments