Check status before decoding Google Analytics accounts

ListGoogleAnalyticsOrganizations decoded the response body into the success
struct before inspecting the HTTP status, unlike every other lister in the
file. Check the status first so a non-2xx no longer wastes a decode against
an error body and the ordering matches the sibling functions.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-07-12 19:42:04 +02:00
parent 21d6542855
commit b6b16cf504

View File

@@ -508,6 +508,12 @@ func ListGoogleAnalyticsOrganizations(ctx context.Context, httpClient *http.Clie
return nil, fmt.Errorf("cannot fetch google analytics accounts: %w", err)
}
if resp.StatusCode != http.StatusOK {
_ = resp.Body.Close()
return nil, fmt.Errorf("cannot fetch google analytics accounts: unexpected status %d", resp.StatusCode)
}
var out struct {
Accounts []struct {
Name string `json:"name"`
@@ -517,13 +523,8 @@ func ListGoogleAnalyticsOrganizations(ctx context.Context, httpClient *http.Clie
}
decodeErr := json.NewDecoder(resp.Body).Decode(&out)
status := resp.StatusCode
_ = resp.Body.Close()
if status != http.StatusOK {
return nil, fmt.Errorf("cannot fetch google analytics accounts: unexpected status %d", status)
}
if decodeErr != nil {
return nil, fmt.Errorf("cannot decode google analytics accounts response: %w", decodeErr)
}