diff --git a/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java b/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java index e5a44529859e7..815441cbad750 100644 --- a/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java +++ b/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java @@ -6,7 +6,6 @@ import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.CONSUMES; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.OBJECT; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.UNI; -import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.WEB_APPLICATION_EXCEPTION; import java.io.Closeable; import java.io.File; @@ -17,7 +16,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -1292,14 +1291,16 @@ private void handleReturn(ClassInfo restClientInterface, String defaultMediaType String mediaTypeValue = defaultMediaType; // if a JAXRS method throws an exception, unwrap the ProcessingException and throw the exception instead - // Similarly with WebApplicationException + // Similarly with RuntimeException's TryBlock tryBlock = methodCreator.tryBlock(); List exceptionTypes = jandexMethod.exceptions(); - Set exceptions = new HashSet<>(); - exceptions.add(WEB_APPLICATION_EXCEPTION); + Set exceptions = new LinkedHashSet<>(); for (Type exceptionType : exceptionTypes) { - exceptions.add(exceptionType.name()); + exceptions.add(exceptionType.name().toString()); + } + if (!exceptions.contains(Exception.class.getName()) && !exceptions.contains(Throwable.class.getName())) { + exceptions.add(RuntimeException.class.getName()); } CatchBlockCreator catchBlock = tryBlock.addCatch(ProcessingException.class); @@ -1307,8 +1308,8 @@ private void handleReturn(ClassInfo restClientInterface, String defaultMediaType ResultHandle cause = catchBlock.invokeVirtualMethod( MethodDescriptor.ofMethod(Throwable.class, "getCause", Throwable.class), caughtException); - for (DotName exception : exceptions) { - catchBlock.ifTrue(catchBlock.instanceOf(cause, exception.toString())) + for (String exception : exceptions) { + catchBlock.ifTrue(catchBlock.instanceOf(cause, exception)) .trueBranch().throwException(cause); } diff --git a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientResponseFilter.java b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientResponseFilter.java index 56c123b4e17a2..61b8d685cfd6f 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientResponseFilter.java +++ b/extensions/resteasy-reactive/rest-client-reactive/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/MicroProfileRestClientResponseFilter.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.util.List; -import javax.ws.rs.ProcessingException; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientResponseContext; import javax.ws.rs.client.ClientResponseFilter; @@ -12,6 +11,7 @@ import org.jboss.resteasy.reactive.client.handlers.ClientResponseCompleteRestHandler; import org.jboss.resteasy.reactive.client.impl.ClientRequestContextImpl; import org.jboss.resteasy.reactive.client.impl.RestClientRequestContext; +import org.jboss.resteasy.reactive.common.core.UnwrappableException; import org.jboss.resteasy.reactive.common.jaxrs.ResponseImpl; public class MicroProfileRestClientResponseFilter implements ClientResponseFilter { @@ -35,7 +35,7 @@ public void filter(ClientRequestContext requestContext, ClientResponseContext re ResponseImpl response = ClientResponseCompleteRestHandler.mapToResponse(restClientContext, false); Throwable throwable = exceptionMapper.toThrowable(response); if (throwable != null) { - throw new ProcessingException(throwable); + throw new UnwrappableException(throwable); } } } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java index 5af64f58d38d4..65ab465b7288d 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java @@ -293,22 +293,30 @@ public H[] getHandlers() { */ public void handleException(Throwable t) { if (handlers == abortHandlerChain) { - handleUnrecoverableError(t); + handleUnrecoverableError(unwrapException(t)); } else { - this.throwable = t; + this.throwable = unwrapException(t); restart(abortHandlerChain); } } public void handleException(Throwable t, boolean keepSameTarget) { if (handlers == abortHandlerChain) { - handleUnrecoverableError(t); + handleUnrecoverableError(unwrapException(t)); } else { - this.throwable = t; + this.throwable = unwrapException(t); restart(abortHandlerChain, keepSameTarget); } } + private Throwable unwrapException(Throwable t) { + if (t instanceof UnwrappableException) { + return t.getCause(); + } + + return t; + } + protected abstract void handleUnrecoverableError(Throwable throwable); public Object getProperty(String name) { diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/UnwrappableException.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/UnwrappableException.java new file mode 100644 index 0000000000000..450c73f39c024 --- /dev/null +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/UnwrappableException.java @@ -0,0 +1,9 @@ +package org.jboss.resteasy.reactive.common.core; + +import javax.ws.rs.ProcessingException; + +public class UnwrappableException extends ProcessingException { + public UnwrappableException(Throwable cause) { + super(cause); + } +} \ No newline at end of file