From b5c99f4020d44301f4e4288d42fc20729ed1108c Mon Sep 17 00:00:00 2001 From: Akash Nagesh Date: Thu, 4 Nov 2021 23:21:06 -0700 Subject: [PATCH] Check for http status code for health-check APIs --- hubclient/health-check-client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hubclient/health-check-client.go b/hubclient/health-check-client.go index b0a417c..920b496 100644 --- a/hubclient/health-check-client.go +++ b/hubclient/health-check-client.go @@ -16,6 +16,8 @@ package hubclient import ( "encoding/json" + "net/http" + "github.com/blackducksoftware/hub-client-go/hubapi" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -39,6 +41,10 @@ func checkHealthStatus(c *Client, url string) (error, *hubapi.HealthCheckStatus) return err, nil } + if resp != nil && resp.StatusCode != http.StatusOK { + return HubClientStatusCodeErrorf(resp.StatusCode, "got a %d response instead of a %d", resp.StatusCode, http.StatusOK), nil + } + if resp != nil { if err := json.NewDecoder(resp.Body).Decode(&status); err == nil { return nil, &status