Copilot commented on code in PR #1433:
URL: https://github.com/apache/pulsar-client-go/pull/1433#discussion_r2471537512


##########
pulsaradmin/pkg/rest/client.go:
##########
@@ -533,6 +539,25 @@ func decodeJSONBody(resp *http.Response, out interface{}) 
error {
        return dec.Decode(out)
 }
 
+// decodeJSONBody is used to JSON decode a body AND ALSO return the raw body 
bytes

Review Comment:
   The comment incorrectly refers to the function as 'decodeJSONBody' but the 
actual function name is 'decodeJSONWithBody'. Update the comment to match the 
function name.
   ```suggestion
   // decodeJSONWithBody is used to JSON decode a body AND ALSO return the raw 
body bytes
   ```



##########
pulsaradmin/pkg/rest/client.go:
##########
@@ -190,12 +194,14 @@ func (c *Client) GetWithOptionsWithContext(
        defer safeRespClose(resp)
 
        if obj != nil {
-               if err := decodeJSONBody(resp, &obj); err != nil {
+               body, err := decodeJSONWithBody(resp, &obj)
+               if err != nil {
                        if err == io.EOF {
                                return nil, nil
                        }
                        return nil, err
                }
+               return body, err

Review Comment:
   Line 204 returns `body, err` unconditionally after the error check. If `err` 
is not nil on line 198-203, the function should have already returned, so this 
line will always execute with `err == nil`. This means the error from 
`decodeJSONWithBody` is being ignored. The function should return the error 
immediately in the error path, or simply return `body, nil` here since any 
error would have already caused an early return.
   ```suggestion
                return body, nil
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to