How to send an application specific error code to clients in grpc-java

39 views
Skip to first unread message

mogw...@gmail.com

unread,
Dec 10, 2019, 10:41:54 PM12/10/19
to grpc.io
Hello,
 
I'm wondering how I can send an application specific error code to clients in grpc-java.

I've been using gprc-java for a few years, but I haven't used onError api in a server
since there seems no way to return application specific error status/code to a client.
(Unless I serialize the code to String and pass it through description or something)

It would be great if experts can give me some advice for this.

Thanks,
Hiro

Eric Anderson

unread,
Dec 11, 2019, 1:33:17 PM12/11/19
to mogw...@gmail.com, grpc.io
You can provide additional details in the Metadata, which can be attached to a StatusException/StatusRuntimeException. You would define a proto message to hold the specific details you care about and then pass it in the Metadata directly on in a google.rpc.Status. See https://stackoverflow.com/a/48750825/4690866 for how that looks.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/9a02e7f4-25ea-4943-8d0e-987122a99e02%40googlegroups.com.

Hiroyuki Yamada

unread,
Dec 11, 2019, 8:38:10 PM12/11/19
to Eric Anderson, grpc.io
Hi Eric,

Thank you very much for the quick response.
Yes, I thought so, but asRuntimeException(metadata) is an experimental API
so I was wondering if there is another better way.
(Seems like StatusProto is also experimental)

Could you (or anyone) give me a hint of how much I can rely on the
experimental APIs for our production use ?
Are they going to be changed quite surely ?

Thanks,
Hiro

Eric Anderson

unread,
Dec 13, 2019, 7:20:00 PM12/13/19
to Hiroyuki Yamada, grpc.io
It is safe for production use. It's just that the API could change.

But I'm surprised it is still experimental. We should stabilize it. It looks like new StatusRuntimeException(Status, Metadata) isn't marked experimental, so you can use that without worrying about future API breakage.

Hiroyuki Yamada

unread,
Dec 15, 2019, 6:50:40 AM12/15/19
to Eric Anderson, grpc.io
Hello Eric,

Thank you for the reply.
Oh, good to know new StatusRuntimeException(Status, Metadata) is not
experimental.
Thank you very much !
Reply all
Reply to author
Forward
0 new messages