Reputation: 2789
I am using the framework in quarkus to build a rest client for the mandrill API
@RegisterRestClient
@Path("1.0")
@Produces("application/json")
@Consumes("application/json")
public interface MailService {
@POST
@Path("/messages/send-template.json")
JsonObject ping(JsonObject mandrillInput);
}
This is the relevant portion of my application.properties
com.example.service.MailService/mp-rest/url=https:/mandrillapp.com/api
And my example resource
@Path("/hello")
public class ExampleResource {
@Inject
@RestClient
MailService mailService;
@Produces(MediaType.TEXT_PLAIN)
@GET
public String hello() {
System.out.print("In the API");
JsonObject key = Json.createObjectBuilder().add("key", "ABCD").build();
System.out.println("The json built is "+key);
JsonObject response = mailService.ping(key);
System.out.println("The response is " + response);
return "hello";
}
}
What I saw is that if the API I am calling (Mandrill in this case) returns an error response (If my key is wrong for example), then the variable I am using to store the response doesnt get the response. Instead the REST API I am exposing to my application wrapping around this, gets populated with the response from Mandrill.
Is this expected behaviour? How can I debug the output of a rest client implementation in Quarkus?
The REST API being called is https://mandrillapp.com/api/docs/users.JSON.html#method=ping2
Upvotes: 2
Views: 2527
Reputation: 64011
If you want to be able to get the body of the response when an error occurs, I suggest you use javax.ws.rs.core.Response
as the response type.
You could also go another route and handle exceptions using ExceptionMapper
Upvotes: 4