grpcgrpc-java

StatusRunTimeException with custom status codes in GRPC


We have an application where we have a need to return Custom GRPC Status codes, as we feel the codes are limited. Is there a way we can return Custom GRPC Status code?

I tried to return custom status code but io.grpc.Status will convert any non-recognized status code to UNKNOW ex:2 UNKNOWN: Unknown code 80

StatusRunTimeException contains Status which accepts only predefined enum values. Has anyone has experience in returning custom status in GRPC?

Found this link - https://github.com/grpc/grpc-java/issues/515 related to custom status codes.


Solution

  • No, custom status codes are not allowed. You list three different ways it was not allowed. It isn't supported.

    Issue 515 also says:

    For custom status information, use Metadata.

    So you can use Metadata instead of a custom status code. The variations of that approach are in Pattern for rich error handling in gRPC .