eclipse / microprofile-rest-client

MicroProfile Rest Client
Apache License 2.0
142 stars 72 forks source link

Clarification for behavior of Default ResponseExceptionMapper when method signature returns Result #345

Closed chonton closed 9 months ago

chonton commented 2 years ago

The spec states that when method signature has Response return type, "..., you can receive the entire Response object for parsing the body and header information from the server invocation."

Elsewhere, the Default ResponseExceptionMapper will "map the response into a WebApplicationException whenever the response status code is >= 400".

What is the expected behavior if a method defined as follows returns a 404?

public interface InventoryClient {
    @GET
    @Path("/lookup")
    Response lookup(@QueryParam("id") String id);
}

(My personal preference is the latter)

chonton commented 2 years ago

Maybe same as #310

andymc12 commented 2 years ago

Hey - sorry for the super-long delay. I switched jobs in the new year, and only get to work on MP Rest Client stuff in my "spare time".

I'm pretty sure that the answer is that the default ResponseExceptionMapper will throw the WebApplicationException - even if the method return type is Response. I agree that that isn't ideal since the client's caller could just handle the Response - whether exception or not.

My only advice to achieve the latter (and probably more desirable) behavior would be to disable the default mapper (either globally or just for certain client interfaces - see the docs for more info: https://download.eclipse.org/microprofile/microprofile-rest-client-2.0/microprofile-rest-client-spec-2.0.html#_default_responseexceptionmapper ) so that no exception will be thrown.

Emily-Jiang commented 9 months ago

The MP Rest Client group met today and decided not to proceed with further changes based on the above comment from @andymc12 . We are going to close it.