scalascalapb

How to handle custom error reporting in ScalaPB's GRPC wrapper


If I have a service's method throw an exception, my client receives no information about what kind of exception this was. I've read that this was made on purpose, to prevent server details being leaked to the client. However, I think it's still useful to give some information to the client, even if only for debugging purposes.

I've seen that io.grpc.Status may be what I'm looking for, but I'm unsure how to "return it" from a service's method, since it really doesn't fit the type signature of the method I'm returning, and it's also not throwable.

Is this usecase suported by scalapb's grpc wrapper? If so, what is the intended way of doing so?


Solution

  • You can throw a io.grpc.StatusException or io.grpc.StatusRuntimeException from your handler. These get a io.grpc.Status which will be sent to the client.