Package net.devh.boot.grpc.server.advice
Class GrpcAdviceExceptionHandler
java.lang.Object
net.devh.boot.grpc.server.advice.GrpcAdviceExceptionHandler
- All Implemented Interfaces:
GrpcExceptionResponseHandler
As part of
@GrpcAdvice, when a thrown exception is caught during gRPC calls (via global
interceptor GrpcExceptionInterceptor), then this thrown exception is being handled. The
GrpcExceptionHandlerMethodResolver provides a mapping for exceptions and their respective handler methods.
The response is derived from methods annotated with GrpcExceptionHandler inside GrpcAdvice beans.
-
Constructor Summary
ConstructorsConstructorDescriptionGrpcAdviceExceptionHandler(GrpcExceptionHandlerMethodResolver grpcExceptionHandlerMethodResolver) Creates a newGrpcAdvicepoweredGrpcExceptionHandler. -
Method Summary
Modifier and TypeMethodDescriptionvoidhandleError(ServerCall<?, ?> serverCall, Throwable error) Handles an exception by closing the call with an appropriateStatus.protected ObjecthandleThrownException(Throwable exception) Given an exception, a lookup is performed to retrieve mapped method.protected voidhandleThrownExceptionByImplementation(ServerCall<?, ?> serverCall, Throwable throwable) protected MetadataresolveMetadata(Object mappedReturnType) protected StatusresolveStatus(Object mappedReturnType)
-
Constructor Details
-
GrpcAdviceExceptionHandler
public GrpcAdviceExceptionHandler(GrpcExceptionHandlerMethodResolver grpcExceptionHandlerMethodResolver) Creates a newGrpcAdvicepoweredGrpcExceptionHandler.- Parameters:
grpcExceptionHandlerMethodResolver- The method resolver to use.
-
-
Method Details
-
handleError
Description copied from interface:GrpcExceptionResponseHandlerHandles an exception by closing the call with an appropriateStatus.- Specified by:
handleErrorin interfaceGrpcExceptionResponseHandler- Parameters:
serverCall- The server call used to send the response status.error- The error to handle.
-
resolveStatus
-
resolveMetadata
-
handleThrownExceptionByImplementation
protected void handleThrownExceptionByImplementation(ServerCall<?, ?> serverCall, Throwable throwable) -
handleThrownException
Given an exception, a lookup is performed to retrieve mapped method.
In case of successful returned method, and matching exception parameter type for given exception, the exception is handed over to retrieved method. Retrieved method is then being invoked.- Parameters:
exception- exception to search for- Returns:
- result of invoked mapped method to given exception
- Throws:
Throwable- rethrows exception if no mapping existent or exceptions raised by implementation
-