In REST, we use HTTP Status Codes (404, 500). In gRPC, we use `RpcException`. But simply throwing exceptions is not enough for rich error details.
The Status Model
Google’s API Design Guide recommends returning a rich `Status` object containing a list of `Any` details.
var status = new Google.Rpc.Status
{
Code = (int)Code.InvalidArgument,
Message = "Invalid Order Request",
Details = {
Any.Pack(new BadRequest { FieldViolations = { ... } })
}
};
throw status.ToRpcException();
This allows the client to deserialize the structured error (e.g., specific field validation errors) rather than parsing a string message.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.