I couldn't find examples with gRPC services, or mention of it not being possible.
It is currently not possible doing that because @ExceptionHandler annotation is for annotated services, which is for building RESTful services with Armeria. However, you can use an interceptor in the official gRPC API or our decorator API.
However, I agree that having such a decorator might be useful for translating exceptions into a response. For example, we wrote a decorator for our Thrift service in our application: https://github.com/line/centraldogma/blob/master/server/src/main/java/com/linecorp/centraldogma/server/internal/thrift/CentralDogmaExceptionTranslator.java
Let me create a feature request issue for you.
An exception raised while serving a gRPC service could be handled by GrpcServiceBuilder.addExceptionMapping() and GrpcServiceBuilder.exceptionMapping(). The new features are released with Armeria 1.3.0.
https://armeria.dev/release-notes/1.3.0
GrpcService.builder()
.addExceptionMapping(AccessDeniedException.class, Status.UNAUTHENTICATED);
// Or, use GrpcStatusFunction.
GrpcService.builder()
.exceptionMapping(cause -> {
if (cause instanceof AccessDeniedException) {
return Status.UNAUTHENTICATED;
}
if (cause instanceof FileNotFoundException) {
return Status.NOT_FOUND;
}
return null; // Return null to use Armeria's default exception mapping.
});
Most helpful comment
See: https://stackoverflow.com/questions/39797142/how-to-add-global-exception-interceptor-in-grpc-server