add exception info to Status.Detail if metadata credentials fail

pull/16543/head
Jan Tattermusch 6 years ago
parent b0aa05b734
commit 4c0d540fb6
  1. 6
      src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
  2. 4
      src/csharp/Grpc.IntegrationTesting/MetadataCredentialsTest.cs

@ -68,7 +68,8 @@ namespace Grpc.Core.Internal
}
catch (Exception e)
{
Native.grpcsharp_metadata_credentials_notify_from_plugin(callbackPtr, userDataPtr, MetadataArraySafeHandle.Create(Metadata.Empty), StatusCode.Unknown, GetMetadataExceptionStatusMsg);
var detail = GetMetadataExceptionStatusMsg + " " + e.ToString();
Native.grpcsharp_metadata_credentials_notify_from_plugin(callbackPtr, userDataPtr, MetadataArraySafeHandle.Create(Metadata.Empty), StatusCode.Unknown, detail);
Logger.Error(e, GetMetadataExceptionLogMsg);
}
}
@ -87,7 +88,8 @@ namespace Grpc.Core.Internal
}
catch (Exception e)
{
Native.grpcsharp_metadata_credentials_notify_from_plugin(callbackPtr, userDataPtr, MetadataArraySafeHandle.Create(Metadata.Empty), StatusCode.Unknown, GetMetadataExceptionStatusMsg);
string detail = GetMetadataExceptionStatusMsg + " " + e.ToString();
Native.grpcsharp_metadata_credentials_notify_from_plugin(callbackPtr, userDataPtr, MetadataArraySafeHandle.Create(Metadata.Empty), StatusCode.Unknown, detail);
Logger.Error(e, GetMetadataExceptionLogMsg);
}
}

@ -153,9 +153,10 @@ namespace Grpc.IntegrationTesting
[Test]
public void MetadataCredentials_InterceptorThrows()
{
var authInterceptorExceptionMessage = "Auth interceptor throws";
var callCredentials = CallCredentials.FromInterceptor(new AsyncAuthInterceptor((context, metadata) =>
{
throw new Exception("Auth interceptor throws");
throw new Exception(authInterceptorExceptionMessage);
}));
var channelCredentials = ChannelCredentials.Create(TestCredentials.CreateSslCredentials(), callCredentials);
channel = new Channel(Host, server.Ports.Single().BoundPort, channelCredentials, options);
@ -163,6 +164,7 @@ namespace Grpc.IntegrationTesting
var ex = Assert.Throws<RpcException>(() => client.UnaryCall(new SimpleRequest { }));
Assert.AreEqual(StatusCode.Unavailable, ex.Status.StatusCode);
StringAssert.Contains(authInterceptorExceptionMessage, ex.Status.Detail);
}
private class FakeTestService : TestService.TestServiceBase

Loading…
Cancel
Save