Skip to content

Commit

Permalink
chore(scorecard): check status code before parsing body in health check
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Feb 12, 2024
1 parent 1f85ea2 commit bdd01c2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/test/scorecard/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,6 @@ func waitTillCryostatReady(base *url.URL, resources *TestResources) error {
}
defer resp.Body.Close()

health := &HealthResponse{}
err = ReadJSON(resp, health)
if err != nil {
return false, fmt.Errorf("failed to read response body: %s", err.Error())
}

if !StatusOK(resp.StatusCode) {
if resp.StatusCode == http.StatusServiceUnavailable {
r.Log += fmt.Sprintf("application is not yet reachable at %s\n", base.String())
Expand All @@ -371,6 +365,12 @@ func waitTillCryostatReady(base *url.URL, resources *TestResources) error {
return false, fmt.Errorf("API request failed with status code %d: %s", resp.StatusCode, ReadError(resp))
}

health := &HealthResponse{}
err = ReadJSON(resp, health)
if err != nil {
return false, fmt.Errorf("failed to read response body: %s", err.Error())
}

if err = health.Ready(); err != nil {
r.Log += fmt.Sprintf("application is not yet ready: %s\n", err.Error())
return false, nil // Try again
Expand Down

0 comments on commit bdd01c2

Please sign in to comment.