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) 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); Logger.Error(e, GetMetadataExceptionLogMsg);
} }
} }
@ -87,7 +88,8 @@ namespace Grpc.Core.Internal
} }
catch (Exception e) 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); Logger.Error(e, GetMetadataExceptionLogMsg);
} }
} }

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

Loading…
Cancel
Save