From c779905163ee3a77378c2c64e8fe5cd2110efea6 Mon Sep 17 00:00:00 2001 From: Joel Caplin Date: Thu, 31 Oct 2013 18:23:44 -0700 Subject: [PATCH] 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. --- src/main/resources/Java/apiInvoker.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/Java/apiInvoker.mustache b/src/main/resources/Java/apiInvoker.mustache index 6dbd0213e19..30dc876a809 100644 --- a/src/main/resources/Java/apiInvoker.mustache +++ b/src/main/resources/Java/apiInvoker.mustache @@ -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.WebResource.Builder; +import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; import java.util.Map; @@ -123,7 +124,7 @@ public class ApiInvoker { else { 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); } else {