title: RestEasyReactive http response returns caught exception
body: <p>I have a simple quarkus reactive resteasy server</p>
  <pre class="lang-java prettyprint-override"><code>@Path(&quot;/&quot;)
  @ApplicationScoped
  public class Hello {
  
      @GET
      @Path(&quot;hello&quot;)
      @RolesAllowed({&quot;roleYouNeed&quot;})
      public Uni&lt;Response&gt; hello(){
          return Uni.createFrom().item(Response.ok(&quot;hello&quot;).build());
      }
  }
          
  </code></pre>
  <p>Following the documentation found here I create several exception mappers to return a response body which elaborates on the status code. This one for example works when you do not provide a JWT token to a request that needs it:</p>
  <pre class="lang-java prettyprint-override"><code>@Provider//register as JAXRS provider
  @Priority(1)//override the build-int mapper(which has 5001 prio)
  @Slf4j
  public class UnauthorizedExceptionMapper implements ExceptionMapper&lt;UnauthorizedException&gt; {
      @Override
      public Response toResponse(UnauthorizedException exception) {
          log.warn(&quot;There was an incoming request that did not have the correct Authorization&quot;);
          return Response.status(Response.Status.UNAUTHORIZED)
                  .entity(new ErrorResponseObject().addErrorsItem(new ErrorResponseObjectErrorsInner()
                          .code(String.valueOf(Response.Status.UNAUTHORIZED.getStatusCode()))
                          .detail(&quot;Unauthorized&quot;)))
                  .build();
      }
  
  }
  </code></pre>
  <p>This works as expected on my endpoint that uses quarkus-smallrye-jwt with the annotation <code>@RolesAllowed({&quot;roleYouNeed&quot;})</code></p>
  <p>When someone sends a token that is truly worthless however a JWTParse Exception occurs and a different exception is raised, the <code>AuthenticationFailedException</code></p>
  <p>To catch this one I created</p>
  <pre class="lang-java prettyprint-override"><code>@Provider
  @Priority(1)
  @Slf4j
  public class AuthenticationExceptionMapper implements ExceptionMapper&lt;AuthenticationFailedException&gt; {
      @Override
      public Response toResponse(AuthenticationFailedException exception) {
          log.warn(&quot;There was an incoming request that did not have the correct Authorization&quot;);
          return Response.status(Response.Status.UNAUTHORIZED)
                  .entity(new ErrorResponseObject().addErrorsItem(new ErrorResponseObjectErrorsInner()
                          .code(String.valueOf(Response.Status.UNAUTHORIZED.getStatusCode()))
                          .detail(&quot;Unauthorized&quot;)))
                  .build();
      }
  }
  </code></pre>
  <p>This does catch the exception and my warning is logged: <code>[com.ene.odp.exc.AuthenticationExceptionMapper] (vert.x-eventloop-thread-0) There was an incoming request that did not have the correct Authorization </code>. The problem here is that a response has already been returned and I see the following error occurring:</p>
  <pre><code>2022-07-25 16:22:03,812 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (vert.x-eventloop-thread-1) Request failed: java.io.IOException: java.io.IOException: Failed to write
          at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveOutputStream.close(ResteasyReactiveOutputStream.java:272)
          at io.quarkus.resteasy.reactive.jackson.runtime.serialisers.BasicServerJacksonMessageBodyWriter.writeResponse(BasicServerJacksonMessageBodyWriter.java:44)
          at org.jboss.resteasy.reactive.server.core.ServerSerialisers.invokeWriter(ServerSerialisers.java:207)
          at org.jboss.resteasy.reactive.server.core.serialization.DynamicEntityWriter.write(DynamicEntityWriter.java:104)
          at org.jboss.resteasy.reactive.server.handlers.ResponseWriterHandler.handle(ResponseWriterHandler.java:31)
          at org.jboss.resteasy.reactive.server.handlers.ResponseWriterHandler.handle(ResponseWriterHandler.java:15)
          at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
          at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:73)
          at org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1$1.handle(VertxResteasyReactiveRequestContext.java:70)
          at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
          at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:63)
          at io.vertx.core.impl.EventLoopContext.lambda$runOnContext$0(EventLoopContext.java:38)
          at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
          at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
          at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:503)
          at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
          at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
          at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
          at java.base/java.lang.Thread.run(Thread.java:833)
  Caused by: java.io.IOException: Failed to write
          at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveOutputStream.write(ResteasyReactiveOutputStream.java:109)
          at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveOutputStream.writeBlocking(ResteasyReactiveOutputStream.java:224)
          at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveOutputStream.close(ResteasyReactiveOutputStream.java:270)
          ... 18 more
  Caused by: java.lang.IllegalStateException: Response has already been written
          at io.vertx.core.http.impl.Http1xServerResponse.checkValid(Http1xServerResponse.java:675)
          at io.vertx.core.http.impl.Http1xServerResponse.writeQueueFull(Http1xServerResponse.java:274)
          at io.quarkus.vertx.http.runtime.filters.AbstractResponseWrapper.writeQueueFull(AbstractResponseWrapper.java:486)
          at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveOutputStream.awaitWriteable(ResteasyReactiveOutputStream.java:116)
          at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveOutputStream.write(ResteasyReactiveOutputStream.java:82)
  </code></pre>
  <p>Why is the response already being returned while I catch this exception? How can I make sure nothing is returned except what I return from the <code>AuthenticationExceptionMapper</code>?</p>