Skip to content

Commit

Permalink
add more error check and type assertion
Browse files Browse the repository at this point in the history
Signed-off-by: charleslin-appd <[email protected]>
  • Loading branch information
charleslin-appd committed Feb 19, 2023
1 parent 134f92e commit 2608dc6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/metrics/providers/appdynamicscloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ func (p *AppDynamicsCloudProvider) RunQuery(query string) (float64, error) {
return 0, fmt.Errorf("invalid response: %s: %w", string(body), ErrNoValuesFound)
}

return metric[1].(float64), nil
// assert the second item of the array is numeric and return
r, ok := metric[1].(float64)
if ok {
return r, nil
} else {
return 0, fmt.Errorf("failed to retrieve numeric result: %s: %w", query, ErrNoValuesFound)
}
}

// IsOnline calls the Appdynamics Cloud's metrics endpoint with client ID and
Expand Down

0 comments on commit 2608dc6

Please sign in to comment.