I have a Rest Client in a Quarkus (1.8.1) service defined like this:
@RegisterRestClient
@Path("/")
@Produces("application/json")
@Consumes("application/json")
public interface MyClient {
@POST
@Path("/{entity}")
Response postEntity(@HeaderParam(value = "Authorization") String auth,
@PathParam("entity") String entity, Object payload) throws MyException;
}
And I have implemented ResponseExceptionMapper
in the same package like this:
public class MyExceptionMapper implements ResponseExceptionMapper<MyException> {
@Override
public MyException toThrowable(Response r) {
return new DynamicsException(r.getStatus() + " - " + r.readEntity(String.class));
}
}
When I call the service it is currently returning a 404 error, and I expected the code in the MyExceptionMapper
class to be called. However it doesn't and instead a javax.ws.rs.WebApplicationException
is thrown. The stack trace includes a call to the DefaultResponseExceptionMapper
. It's seems that my mapper has not been registered.
How can I register my handler for invalid responses from calls to the service?
You need to register MyExceptionMapper as provider to the rest client with
@RegisterProvider(MyExceptionMapper.class)
.