Skip to content

Commit c779905

Browse files
author
Joel Caplin
committed
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.
1 parent 59da358 commit c779905

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/resources/Java/apiInvoker.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig;
1212
import com.sun.jersey.api.client.filter.LoggingFilter;
1313
import com.sun.jersey.api.client.WebResource.Builder;
1414

15+
import javax.ws.rs.core.Response.Status.Family;
1516
import javax.ws.rs.core.MediaType;
1617

1718
import java.util.Map;
@@ -123,7 +124,7 @@ public class ApiInvoker {
123124
else {
124125
throw new ApiException(500, "unknown method type " + method);
125126
}
126-
if(response.getClientResponseStatus() == ClientResponse.Status.OK) {
127+
if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
127128
return (String) response.getEntity(String.class);
128129
}
129130
else {

0 commit comments

Comments
 (0)