Class GrpcExceptionHandlerInterceptor

java.lang.Object
org.springframework.grpc.server.exception.GrpcExceptionHandlerInterceptor
All Implemented Interfaces:
io.grpc.ServerInterceptor

@Order(-2147483648) public class GrpcExceptionHandlerInterceptor extends Object implements io.grpc.ServerInterceptor
A gRPC ServerInterceptor that handles exceptions thrown during the processing of gRPC calls. It intercepts the call and wraps the ServerCall.Listener with an GrpcExceptionHandlerInterceptor.ExceptionHandlerListener that catches exceptions in onMessage and onHalfClose methods, and delegates the exception handling to the provided GrpcExceptionHandler.

A fallback mechanism is used to return UNKNOWN in case the GrpcExceptionHandler returns a null.

Author:
Dave Syer, Andrey Litvitski
See Also:
  • Constructor Details

    • GrpcExceptionHandlerInterceptor

      public GrpcExceptionHandlerInterceptor(GrpcExceptionHandler exceptionHandler)
  • Method Details

    • interceptCall

      public <ReqT,RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT,RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT,RespT> next)
      Intercepts a gRPC server call to handle exceptions.
      Specified by:
      interceptCall in interface io.grpc.ServerInterceptor
      Type Parameters:
      ReqT - the type of the request message
      RespT - the type of the response message
      Parameters:
      call - the server call object
      headers - the metadata headers for the call
      next - the next server call handler in the interceptor chain
      Returns:
      a listener for the request messages