I would like to give some more detailed information to the client about what was wrong in the server.
In my case, the server use domain classes to perform some action. I would like to send to the client the text of the exception that the domain class throw to the gRPC service.
This is my code in the gRPC class:
catch (Exception e)
{
var correlationId = Guid.NewGuid();
//_logger.LogError(e, "CorrelationId: {0}", correlationId);
var trailers = new Metadata();
trailers.Add("CorrelationId", correlationId.ToString());
// Adding the correlation to Response Trailers
throw new RpcException(new Status(StatusCode.Internal,
$"Error message sent to the client with a CorrelationId:{correlationId}"),
//trailers,
//Este es el texto que le llegará al cliente.
"My message for the client.");
}
But in my client, in the GrpcException, I don't get the text "My message for the client.". I expected to recive it in the Message property of the exception, but I get the same information than in the Status property.
Status property: {Status(StatusCode="Internal", Detail="Error message sent to the client with a CorrelationId:dc25a487-cbf3-4670-803e-cac8ef8420c5")}
Message: "Status(StatusCode=\"Internal\", Detail=\"Error message sent to the client with a CorrelationId:dc25a487-cbf3-4670-803e-cac8ef8420c5\")"
In the program.cs file of my ASP Core, that hosts the gRPC serivice, I have try to configure to send details to the client, but the behavior is the same in I configure or not.
I am using code first grpc too.
This is the code in my program.cs file:
builder.Services.AddGrpc(options =>
{
options.EnableDetailedErrors = true;
});
builder.Services.AddCodeFirstGrpc(configureOptions =>
{
configureOptions.EnableDetailedErrors = true;
});
By default, grpc doesn't send the message of an exception caught in the server side handler to the client. This is mostly for security, since an exception message could easily expose some implementation details about the server that you don't want exposed.
If want to pass any of the information to the server, you can either: