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 newGrpcAdvice
poweredGrpcExceptionHandler
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
handleError
(ServerCall<?, ?> serverCall, Throwable error) Handles an exception by closing the call with an appropriateStatus
.protected Object
handleThrownException
(Throwable exception) Given an exception, a lookup is performed to retrieve mapped method.protected void
handleThrownExceptionByImplementation
(ServerCall<?, ?> serverCall, Throwable throwable) protected Metadata
resolveMetadata
(Object mappedReturnType) protected Status
resolveStatus
(Object mappedReturnType)
-
Constructor Details
-
GrpcAdviceExceptionHandler
public GrpcAdviceExceptionHandler(GrpcExceptionHandlerMethodResolver grpcExceptionHandlerMethodResolver) Creates a newGrpcAdvice
poweredGrpcExceptionHandler
.- Parameters:
grpcExceptionHandlerMethodResolver
- The method resolver to use.
-
-
Method Details
-
handleError
Description copied from interface:GrpcExceptionResponseHandler
Handles an exception by closing the call with an appropriateStatus
.- Specified by:
handleError
in 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
-