I'm using quarkus both server and client rest reactive to implement a microservice which calls an upstream api.
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
I want to process BadRequest error from the upstream service and return a different error to my client.
The rest client to the upstream API can throw a org.jboss.resteasy.reactive.ClientWebApplicationException which is 'caused by' the javax.ws.rs.WebApplicationException: (Bad Request, status code 400)
With a ResponseExceptionMapper, the rest client to the upstream API throws javax.ws.rs.ProcessingException which is 'caused by' the exception created by the Mapper.
To handle both cases, I find I must do the following:
Uni.createFrom().item(upstream.getData())
.onFailure(ClientWebApplicationException.class).transform(e -> e.getCause())
.onFailure(WebApplicationException.class).transform(this::makeClientSideException)
.onFailure(ProcessingException.class).transform(e -> e.getCause())
.onFailure(MyCustomException.class).transform(this::makeClientSideException)
I prefer the caused-by classes directly in my service layer code. Is the following possible? How can I make it so?
Uni.createFrom().item(upstream.getData())
.onFailure(WebApplicationException.class).transform(this::makeClientSideException)
.onFailure(MyCustomException.class).transform(this::makeClientSideException)
Thank-you for regarding my question.
FYI: The rest client,
@RegisterRestClient
@RegisterProvider(MyCustomExceptionMapper.class)
public interface upstream {
Uni<MyData> getData();
}
class MyCustomExceptionMapper extends ResponseExceptionMapper<MyCustomException> {...}