Skip to content

Commit 7aea499

Browse files
jeanbzadfawley
authored andcommitted
credentials: return Unavailable instead of Internal for per-RPC creds errors (grpc#1776)
Or if `PerRPCCredentials` returns a `status` error, honor that instead.
1 parent c998149 commit 7aea499

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

credentials/credentials.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ type PerRPCCredentials interface {
4343
// GetRequestMetadata gets the current request metadata, refreshing
4444
// tokens if required. This should be called by the transport layer on
4545
// each request, and the data should be populated in headers or other
46-
// context. uri is the URI of the entry point for the request. When
47-
// supported by the underlying implementation, ctx can be used for
46+
// context. If a status code is returned, it will be used as the status
47+
// for the RPC. uri is the URI of the entry point for the request.
48+
// When supported by the underlying implementation, ctx can be used for
4849
// timeout and cancellation.
4950
// TODO(zhaoq): Define the set of the qualified keys instead of leaving
5051
// it as an arbitrary string.

transport/http2_client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,11 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
380380
for _, c := range t.creds {
381381
data, err := c.GetRequestMetadata(ctx, audience)
382382
if err != nil {
383-
return nil, streamErrorf(codes.Internal, "transport: %v", err)
383+
if _, ok := status.FromError(err); ok {
384+
return nil, err
385+
}
386+
387+
return nil, streamErrorf(codes.Unauthenticated, "transport: %v", err)
384388
}
385389
for k, v := range data {
386390
// Capital header names are illegal in HTTP/2.

0 commit comments

Comments
 (0)