Skip to content

Commit

Permalink
Refactor Azure error handling in gatherAzure function
Browse files Browse the repository at this point in the history
  • Loading branch information
mirackara committed Apr 26, 2024
1 parent abd9719 commit a884592
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions v3/internal/utilization/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func gatherAzure(util *Data, client *http.Client) error {
if err != nil {
// Only return the error here if it is unexpected to prevent
// warning customers who aren't running Azure about a timeout.
// If any of the other vendors have been detected, and we have an unauthorized error, we should not return the error
// If any of the other vendors have already been detected and set, and we have an error, we should not return the error
// If no vendors have been detected, we should return the error.
if _, ok := err.(unexpectedAzureErr); ok && !util.Vendors.AnySet() {
return err
Expand Down Expand Up @@ -61,14 +61,10 @@ func getAzure(client *http.Client) (*azure, error) {
}
defer response.Body.Close()

if response.StatusCode != 200 && response.StatusCode != 401 {
if response.StatusCode != 200 {
return nil, unexpectedAzureErr{e: fmt.Errorf("response code %d", response.StatusCode)}
}

if response.StatusCode == 401 {
return nil, unexpectedAzureErr{e: err}
}

data, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, unexpectedAzureErr{e: err}
Expand Down

0 comments on commit a884592

Please sign in to comment.