Hi,
I'm trying to add a C# interceptor that will handle refreshing an access
token if it was expired.
Here is my current code:
public override AsyncServerStreamingCall<TResponse>
AsyncServerStreamingCall<TRequest, TResponse>(
TRequest request, ClientInterceptorContext<TRequest, TResponse>
context,
AsyncServerStreamingCallContinuation<TRequest, TResponse>
continuation)
{
var cancellationToken = context.Options.CancellationToken;
var token = Task.Run(() => GetAccessTokenAsync(cancellationToken
), cancellationToken).Result;
if (token.IsMissing())
if (Task.Run(() => RefreshTokensAsync(cancellationToken),
cancellationToken).Result == false)
_logger.Warn("Unable to refresh access token");
AddOrUpdateHeader(context.Options.Headers,
CreateBearerTokenHeader(token));
try
{
return continuation(request, context);
}
catch (RpcException e) when (e.StatusCode == StatusCode.
Unauthenticated)
{
if (Task.Run(() => RefreshTokensAsync(cancellationToken),
cancellationToken).Result == false)
_logger.Warn("Unable to refresh access token");
AddOrUpdateHeader(context.Options.Headers,
CreateBearerTokenHeader(AccessToken));
return continuation(request, context);
}
}
What is surprising to me is that the RpcException that is thrown is never
caught by the exception handler (it is caught by the client however).
Could anyone suggest what I'm missing? Or point to an example of a server
streaming retry handler in C#.
Thanks,
Mark
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/0f6d0e17-eaf1-4ad5-8ea3-9b7369ccbf9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.