2

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

bobby
  • 2,629
  • 5
  • 30
  • 56
  • Can you add some example code showing what you are describing? Asking because I don't really understand what the problem is. – geoand May 05 '20 at 07:23
  • @geoand updated the example – bobby May 05 '20 at 08:53
  • I see, thanks @bobby. And what is the behavior you are after when an error happens? An exception being thrown or something else? – geoand May 05 '20 at 11:35
  • @geoand If I use an invalid key like in the example, mailService.ping() never returns. What I see is that the caller of the API (I used curl) gets the response which was returned by mandrill. I dont see any exceptions being printed in the quarkus console. My assumption was the failure response from mandrill would get populated in the response object. But this is not the case – bobby May 05 '20 at 12:58

1 Answers1

4

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

geoand
  • 60,071
  • 24
  • 172
  • 190
  • 1
    For me what worked, was declaring the Rest client function to throw a WebApplicationException, and then handling that where the API was being called – bobby May 06 '20 at 08:12