tpodowd commented on code in PR #9748:
URL: https://github.com/apache/cloudstack/pull/9748#discussion_r1805911585


##########
plugins/integrations/cloudian/src/main/java/org/apache/cloudstack/cloudian/client/CloudianClient.java:
##########
@@ -287,33 +492,42 @@ public CloudianGroup listGroup(final String groupId) {
         try {
             final HttpResponse response = 
get(String.format("/group?groupId=%s", groupId));
             checkResponseOK(response);
-            if (checkEmptyResponse(response)) {
-                return null;
+            if (noResponseEntity(response)) {
+                return null; // Group Not Found
             }
             final ObjectMapper mapper = new ObjectMapper();
             return mapper.readValue(response.getEntity().getContent(), 
CloudianGroup.class);
         } catch (final IOException e) {
             logger.error("Failed to list Cloudian group due to:", e);
-            checkResponseTimeOut(e);
+            throwTimeoutOrServerException(e);
+            return null; // never reached
         }
-        return null;
     }
 
     public List<CloudianGroup> listGroups() {
         logger.debug("Trying to list Cloudian groups");
         try {
             final HttpResponse response = get("/group/list");
             checkResponseOK(response);
-            if (checkEmptyResponse(response)) {
-                return new ArrayList<>();
+            if (noResponseEntity(response)) {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "API 
error");
+            }
+            // The empty list case is badly behaved and returns as 200 with an 
empty body.
+            // We'll try detect this by reading the first byte and then 
putting it back if required.
+            PushbackInputStream iStream = new 
PushbackInputStream(response.getEntity().getContent());
+            int firstByte=iStream.read();
+            if (firstByte == -1) {
+                return new ArrayList<>(); // EOF => empty list
             }
+            // unread that first byte and process the JSON
+            iStream.unread(firstByte);

Review Comment:
   Sure. I'll do that also.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to