Open tombry opened 6 years ago
Does only Go supports this? I can't seem to find much details for other languages.
+1 for client\server examples of handling details In Java it is also supported this via:
Status s = com.google.rpc.Status.newBuilder()
.setCode(com.google.rpc.Code.INVALID_ARGUMENT.getNumber())
.setMessage("Invalid age")
.addDetails(Any.pack(BadRequest.newBuilder()
.addFieldViolations(BadRequest.FieldViolation
.newBuilder()
.setField("age")
.setDescription("age must be positive ")
.build()
).build()
)
).build();
throw io.grpc.protobuf.StatusProto.toStatusRuntimeException(s);
Yes, I would like this for C#, it's really hard to figure out. I guess google.rpc.Status should be inserted in trailers, and embedding e.g. google.rpc.BadRequest inside that.
But no examples anywhere.
I think google.rpc.BadRequest with field violations is so fundamental error type that example of it's usage should be shown.
Hey!
So, gRPC docs finally added few more details on rich error handling - https://grpc.io/docs/guides/error/#richer-error-model
According to the docs:
This richer error model is already supported in the C++, Go, Java, Python, and Ruby libraries, and at least the grpc-web and Node.js libraries have open issues requesting it.
I have started working on and opened a PR - #15
I have added Go and Python examples for now and other language examples later. If anyone interested doing same for C++, Java or Ruby, please let me know. Thank you!
Theses examples are great! I wish that the grpc project would fold them into the standard language quick start or tutorials.
I see that the examples seem to focus on setting the error code and message, but the Status now supports additional details: https://godoc.org/google.golang.org/grpc/status#Status.Details.
Have you considered extending the examples to show how to set and retrieve these details? I'm personally interested in Python and Go at the moment, but I guess you'd want to expand all of the examples at once.