Skip to content

Commit

Permalink
Log out the response in the error case.
Browse files Browse the repository at this point in the history
  • Loading branch information
bigkevmcd committed Mar 1, 2023
1 parent 0c673b0 commit 700a8e0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions controllers/templates/generators/apiclient/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ func (g *APIClientGenerator) Generate(ctx context.Context, sg *templatesv1.GitOp
}
defer resp.Body.Close()

// Anything 400+ is an error?
if resp.StatusCode >= http.StatusBadRequest {
// TODO: this should read the body and insert it?
g.Logger.Info("failed to fetch endpoint", "endpoint", sg.APIClient.Endpoint, "statusCode", resp.StatusCode)
return nil, fmt.Errorf("got %d response from endpoint %s", resp.StatusCode, sg.APIClient.Endpoint)
}

body, err := io.ReadAll(resp.Body)
if err != nil {
g.Logger.Error(err, "failed to read response", "endpoint", sg.APIClient.Endpoint)
return nil, err
}

// Anything 400+ is an error?
if resp.StatusCode >= http.StatusBadRequest {
g.Logger.Info("failed to fetch endpoint", "endpoint", sg.APIClient.Endpoint, "statusCode", resp.StatusCode, "response", string(body))
return nil, fmt.Errorf("got %d response from endpoint %s", resp.StatusCode, sg.APIClient.Endpoint)
}

if sg.APIClient.JSONPath == "" {
return g.generateFromResponseBody(body, sg.APIClient.Endpoint)
}
Expand Down

0 comments on commit 700a8e0

Please sign in to comment.