Rationalize response status code check. Ensure that all bona fide 2xx responses are treated in the same way that "200 OK" is.

Previously, was explicitly checking for response code 200 (ClientResponse.Status.OK).

Now, checks the family of the response to make sure it is successful (Family.SUCCESSFUL). This enables us to POST to resources that return 201 created - without having to handle a checked ApiException.
This commit is contained in:
Joel Caplin 2013-10-31 18:23:44 -07:00
parent 59da358eb5
commit c779905163

View File

@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.api.client.WebResource.Builder; import com.sun.jersey.api.client.WebResource.Builder;
import javax.ws.rs.core.Response.Status.Family;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.Map; import java.util.Map;
@ -123,7 +124,7 @@ public class ApiInvoker {
else { else {
throw new ApiException(500, "unknown method type " + method); throw new ApiException(500, "unknown method type " + method);
} }
if(response.getClientResponseStatus() == ClientResponse.Status.OK) { if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
return (String) response.getEntity(String.class); return (String) response.getEntity(String.class);
} }
else { else {