Table of Contents

gRPC Rich Error

Adds support for the richer gRPC error model to gRPC for .NET via extension methods.

Usage

Add a reference to the GrpcRichError package to your project and use the namespace:

using GrpcRichError;

To throw an RPC exception with rich error details:

throw new Google.Rpc.Status
{
    Code = (int)StatusCode.NotFound,
    Message = "some message",
    Details =
    {
        new ErrorInfo
        {
            Domain = "example.com",
            Reason = "some reason"
        },
        new BadRequest
        {
            // ...
        }
    }
}.ToException();

To extract rich error details from an RPC exception:

try
{
    // ...
}
catch (RpcException ex)
{
    var info = ex.GetDetail<ErrorInfo>();
    if (info != null)
    {
        // ...
    }
}