Coding for handling errors
You may have already gone through the theory-based Handling errors and error status codes section in Chapter 10, Getting Started with gRPC, where google.rpc.Status
and gRPC status codes were discussed. You may want to revisit that section before going through this section as here you are going to write the actual code.
io.grpc.ServerInterceptor
is a thread-safe interface for intercepting incoming calls that can be used for cross-cutting calls, such as authentication and authorization, logging, and monitoring. Let’s use it to write ExceptionInterceptor
, as shown in the following code block:
@Componentpublic class ExceptionInterceptor implements ServerInterceptor { @Override public <RQT, RST> ServerCall.Listener<RQT> interceptCall( ServerCall<RQT, RST> serverCall, Metadata metadata, ServerCallHandler<RQT, RST> serverCallHandler...