Skip to content

Commit

Permalink
Add option to configure log level of WebApplicationException.
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Huginn committed Jul 25, 2023
1 parent ab18d1b commit e8bac0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions docs/src/main/asciidoc/resteasy-reactive.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,16 @@ public class Endpoint {
}
----

[NOTE]
====
You can change the log level of the thrown `WebApplicationException` exceptions by configuring the following property `quarkus.log.category."WebApplicationException".level` like so:
[source, properties]
----
quarkus.log.category."WebApplicationException".level=DEBUG
----
====

If your endpoint method is delegating calls to another service layer which
does not know of Jakarta REST, you need a way to turn service exceptions to an
HTTP response, and you can do that using the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;

import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.container.CompletionCallback;
import jakarta.ws.rs.container.ConnectionCallback;

Expand All @@ -22,6 +23,7 @@
public abstract class AbstractResteasyReactiveContext<T extends AbstractResteasyReactiveContext<T, H>, H extends RestHandler<T>>
implements Runnable, Closeable, ResteasyReactiveCallbackContext {
protected static final Logger log = Logger.getLogger(AbstractResteasyReactiveContext.class);
protected static final Logger logWebApplicationExceptions = Logger.getLogger(WebApplicationException.class.getSimpleName());
protected H[] handlers;
protected H[] abortHandlerChain;
protected int position;
Expand Down Expand Up @@ -322,7 +324,11 @@ public void handleException(Throwable t, boolean keepSameTarget) {
handleUnrecoverableError(unwrapException(t));
} else {
this.throwable = unwrapException(t);
log.debug("Restarting handler chain for exception exception", this.throwable);
if (t instanceof WebApplicationException) {
logWebApplicationExceptions.debug("Restarting handler chain for exception exception", this.throwable);
} else {
log.debug("Restarting handler chain for exception exception", this.throwable);
}
abortHandlerChainStarted = true;
restart(abortHandlerChain, keepSameTarget);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class RuntimeExceptionMapper {

private static final Logger log = Logger.getLogger(RuntimeExceptionMapper.class);
private static final Logger logWebApplicationExceptions = Logger.getLogger(WebApplicationException.class.getSimpleName());

private static Map<Class<? extends Throwable>, ResourceExceptionMapper<? extends Throwable>> mappers;

Expand Down Expand Up @@ -102,7 +103,7 @@ public void mapException(Throwable throwable, ResteasyReactiveRequestContext con
if ((IGNORE_RESPONSE == response)) {
if (isWebApplicationException) {
context.setResult(((WebApplicationException) throwable).getResponse());
log.debug("Application failed the request", throwable);
logWebApplicationExceptions.debug("Application failed the request", throwable);
} else {
logBlockingErrorIfRequired(throwable, context);
logNonBlockingErrorIfRequired(throwable, context);
Expand All @@ -117,7 +118,7 @@ public void mapException(Throwable throwable, ResteasyReactiveRequestContext con
}
if (isWebApplicationException) {
context.setResult(response);
log.debug("Application failed the request", throwable);
logWebApplicationExceptions.debug("Application failed the request", throwable);
return;
}
if (throwable instanceof IOException) {
Expand Down

0 comments on commit e8bac0a

Please sign in to comment.