I would like to know if there is a pattern for field validation in grpc services.
I know that RpcException has metadata trailers property and that I can add additional information about my errors.
My question is: There is a pattern to be followed? If not, Which of the examples below would be more in line with the expected.
Example 1:
Metadata trailers = new Metadata();
trailers.Add("Name", "is required");
trailers.Add("Age", "is required");
trailers.Add("Age", "must be over 21");
throw new RpcException(new Status(StatusCode.InvalidArgument, "Invalid Argument"), trailers, "One or more errors");
Example 2:
Metadata trailers = new Metadata();
trailers.Add("errors", @"{""Name"":[""Is required""],""Age"":[""Is required"",""must be over 21""]}");
throw new RpcException(new Status(StatusCode.InvalidArgument, "Invalid Argument"), trailers, "One or more errors");
I would like to take this response and convert it to a json using the RFC 7807 specification when needed