Class GrpcAdviceExceptionHandler

java.lang.Object
org.springframework.grpc.server.advice.GrpcAdviceExceptionHandler
All Implemented Interfaces:
GrpcExceptionHandler

public class GrpcAdviceExceptionHandler extends Object implements GrpcExceptionHandler
Handles exceptions by delegating to @GrpcExceptionHandler methods in @GrpcAdvice beans.
Author:
Oleksandr Shevchenko
See Also:
  • Constructor Details

    • GrpcAdviceExceptionHandler

      public GrpcAdviceExceptionHandler(GrpcExceptionHandlerMethodResolver grpcExceptionHandlerMethodResolver)
      Create a new instance.
      Parameters:
      grpcExceptionHandlerMethodResolver - the method resolver to use
  • Method Details

    • handleException

      public @Nullable io.grpc.StatusException handleException(Throwable exception)
      Description copied from interface: GrpcExceptionHandler
      Handle the given exception that occurred during gRPC server-side processing.
      Specified by:
      handleException in interface GrpcExceptionHandler
      Parameters:
      exception - the exception to handle
      Returns:
      the status to return to the client, or null if the exception cannot be classified
    • resolveStatus

      protected io.grpc.Status resolveStatus(Object mappedReturnType)
      Resolve the gRPC status from the handler's return value.
      Parameters:
      mappedReturnType - the handler return value
      Returns:
      the resolved status
    • resolveMetadata

      protected io.grpc.Metadata resolveMetadata(Object mappedReturnType)
      Resolve the metadata from the handler's return value.
      Parameters:
      mappedReturnType - the handler return value
      Returns:
      the resolved metadata, or empty metadata
    • handleThrownException

      protected @Nullable Object handleThrownException(Throwable exception) throws Throwable
      Look up and invoke the handler method for the given exception.
      Parameters:
      exception - the exception to handle
      Returns:
      the handler result, or null if no handler is mapped
      Throws:
      Throwable - if the handler throws an exception