title: ServerInterceptor gRPC not catching exceptions with SmallRye Mutiny Reactive in Quarkus
body: <p>I have two gRPC endpoints available, and a ServerInterceptor which should intercept exceptions when thrown.</p>
  <p>The gRPC service is defined as following:</p>
  <pre><code>@GrpcService
  public class AccountsResource implements AccountsApiService {
  
      @Inject
      AccountsService accountsService;
  
      @Override
      public Uni&lt;GetTppPlatformGroupIdResponse&gt; getTppPlatformGroupId(Empty request) {
          Context.Key&lt;String&gt; tppIamClientIdKey = Constant.TPP_IAM_CLIENT_ID_CONTEXT_KEY;
          String tppIamClientId = tppIamClientIdKey.get(Context.current());
  
          return Uni.createFrom().item(() -&gt; accountsService.getTppPlatformGroupIdResponse(tppIamClientId))
                  .runSubscriptionOn(Infrastructure.getDefaultExecutor());
      }
  }
  </code></pre>
  <p>The gRPC service uses SmallRye Mutiny Reactive for handling of the requests.</p>
  <p>Other posts explained that the <code>onHalfClose</code> method should be overridden and a try/catch block inserted to catch custom exceptions, which are then mappen to the StatusRuntimeException gRPC can work with. I tried the following:</p>
  <pre><code>@ApplicationScoped
  @GlobalInterceptor
  public class ExceptionInterceptor implements ServerInterceptor {
  
      private static final Logger LOG = LogManager.getLogger(ExceptionInterceptor.class);
  
      @Override
      public &lt;ReqT, RespT&gt; ServerCall.Listener&lt;ReqT&gt; interceptCall(ServerCall&lt;ReqT, RespT&gt; serverCall, Metadata metadata, ServerCallHandler&lt;ReqT, RespT&gt; serverCallHandler) {
          ServerCall.Listener&lt;ReqT&gt; listener = serverCallHandler.startCall(serverCall, metadata);
          return new ExceptionHandlingServerCallListener&lt;&gt;(listener, serverCall, metadata);
      }
  
      private class ExceptionHandlingServerCallListener&lt;ReqT, RespT&gt; extends ForwardingServerCallListener.SimpleForwardingServerCallListener&lt;ReqT&gt; {
          private ServerCall&lt;ReqT, RespT&gt; serverCall;
          private Metadata metadata;
  
          ExceptionHandlingServerCallListener(ServerCall.Listener&lt;ReqT&gt; listener, ServerCall&lt;ReqT, RespT&gt; serverCall, Metadata metadata) {
              super(listener);
              this.serverCall = serverCall;
              this.metadata = metadata;
          }
  
          @Override
          public void onHalfClose() {
              try {
                  super.onHalfClose();
              } catch (Throwable ex) {
                  handleException(ex, serverCall, metadata);
              }
          }
  
          @Override
          public void onReady() {
              try {
                  super.onReady();
              } catch (Throwable ex) {
                  handleException(ex, serverCall, metadata);
              }
          }
      }
  </code></pre>
  <p>The <code>handleException</code> method maps the Throwable to the StatusRuntimeException and throws the StatusRuntimeException.</p>
  <p>So far so good, and when running the application and simulating a custom exception the ExceptionInterceptor does enter the <code>onHalfClose</code> method. It does not however, go into the catch block even though an exception has been thrown. This error message is logged to the console instead:</p>
  <p><code>2022-01-24 12:07:36,232 WARN  [io.qua.grp.run.ServerCalls] (executor-thread-0) gRPC service threw an exception other than StatusRuntimeException</code></p>
  <p>How can this be fixed?</p>