diff --git a/pkg/accessreview/drivers/organizations.go b/pkg/accessreview/drivers/organizations.go index 93e883c5d..bf96c985f 100644 --- a/pkg/accessreview/drivers/organizations.go +++ b/pkg/accessreview/drivers/organizations.go @@ -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) }