Skip to content

Commit

Permalink
Unwrap processing exception from REST Client when returning a Uni
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Mar 6, 2024
1 parent 22dcfe1 commit 3e60238
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.smallrye.mutiny.Uni;

public class ResponseExceptionMapperTest {
@RegisterExtension
Expand All @@ -34,8 +35,11 @@ public class ResponseExceptionMapperTest {

@Test
void shouldInvokeExceptionMapperOnce() {
assertThrows(RuntimeException.class, client::get);
assertThrows(TestException.class, client::get);
assertThat(MyExceptionMapper.executionCount.get()).isEqualTo(1);

assertThrows(TestException.class, () -> client.uniGet().await().indefinitely());
assertThat(MyExceptionMapper.executionCount.get()).isEqualTo(2);
}

@Path("/error")
Expand All @@ -51,6 +55,9 @@ public Response returnError() {
public interface Client {
@GET
String get();

@GET
Uni<String> uniGet();
}

@Provider
Expand All @@ -61,7 +68,14 @@ public static class MyExceptionMapper implements ResponseExceptionMapper<Excepti
@Override
public Exception toThrowable(Response response) {
executionCount.incrementAndGet();
return new RuntimeException("My exception");
return new TestException("My exception");
}
}

public static class TestException extends RuntimeException {

public TestException(String message) {
super(message);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.jboss.resteasy.reactive.client.impl;

import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import java.util.function.Supplier;

import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;
Expand All @@ -25,6 +27,14 @@ public <R> Uni<R> method(String name, Entity<?> entity, GenericType<R> responseT
public CompletionStage<R> get() {
return invoker.method(name, entity, responseType);
}
}).onFailure().transform(new Function<>() {
@Override
public Throwable apply(Throwable t) {
if ((t instanceof ProcessingException) && (t.getCause() != null)) {
return t.getCause();
}
return t;
}
});
}

Expand Down

0 comments on commit 3e60238

Please sign in to comment.