I want to handle all errors in a uniform format. For this I use @ServerExceptionMapper for classes: Exception, WebApplicationException, NotFoundException,... But there are errors that don't get into my handlers.
For example, request for non-existent url returns an error bypassing my @ServerExceptionMapper(value = {NotFoundException.class})
With this request, we get into the class method, where the response is filled:
io.undertow.servlet.spec.HttpServletResponseImpl (quarkus-http-servlet-4.1.7.jar)
public void doErrorDispatch(int sc, String error){
//...
this.setContentType("text/html");
this.setCharacterEncoding("UTF-8");
if (this.servletContext.getDeployment().getDeploymentInfo().isEscapeErrorMessage()) {
this.getWriter().write("<html><head><title>Error</title></head><body>" + escapeHtml(error) + "</body></html>");
} else {
this.getWriter().write("<html><head><title>Error</title></head><body>" + error + "</body></html>");
}
this.getWriter().close();
And then we get into the class method, where the response is returned: io.vertx.core.http.impl.Http1xServerResponse(vertx-core-4.2.7.jar)
public Future<Void> end(Buffer chunk)
Second example. Authorisation Error. It is intercepted in a class method: io.quarkus.vertx.http.runtime.security.HttpSecurityRecorder (quarkus-vertx-http-2.7.6.Final.jar)
public Handler<RoutingContext> authenticationMechanismHandler(boolean proactiveAuthentication){
//...
event.put("io.quarkus.vertx.http.auth-failure-handler", new BiConsumer<RoutingContext, Throwable>() {
public void accept(RoutingContext routingContext, Throwable throwable) {
throwable = HttpSecurityRecorder.this.extractRootCause(throwable);
if (throwable instanceof AuthenticationFailedException) {
authenticator.sendChallenge(event).subscribe().with(new Consumer<Boolean>() {
public void accept(Boolean aBoolean) {
if (!event.response().ended()) {
event.response().end();
event.response().end() - also gets into the method end() of the class io.vertx.core.http.impl.Http1xServerResponse
How can I make sure that all errors are handled by my mappers?
I watched the article https://quarkus.io/guides/resteasy-reactive. I tried adding a @ServerResponseFilter and WriterInterceptor, but it didn't work. They also don't handle all exceptions.