Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
// Because the service availability can return an error (which we ignore),
// then we need to check for the 'no error' scenarios.
if err == nil {
if c.StatusCheckCode > 0 && status != c.StatusCheckCode {
if validStatusCodeRange(c.StatusCheckCode) && status != c.StatusCheckCode {
// If the user set a specific status code expectation...
text.Warning(out, "The service path `%s` responded with a status code (%d) that didn't match what was expected (%d).", c.StatusCheckPath, status, c.StatusCheckCode)
} else if c.StatusCheckCode == 0 && status >= http.StatusBadRequest {
} else if !validStatusCodeRange(c.StatusCheckCode) && status >= http.StatusBadRequest {
// If no status code was specified, and the actual status response was an error...
text.Info(out, "The service path `%s` responded with a non-successful status code (%d). Please check your application code if this is an unexpected response.", c.StatusCheckPath, status)
}
Expand All @@ -204,6 +204,13 @@ func (c *DeployCommand) Exec(in io.Reader, out io.Writer) (err error) {
return nil
}

func validStatusCodeRange(status int) bool {
if status >= 100 && status <= 999 {
return true
}
return false
}

// setupDeploy prepares the environment.
// It will do things like:
// - Check if there is an API token missing.
Expand Down Expand Up @@ -1177,7 +1184,7 @@ func checkingServiceAvailability(
spinner.Message(msg + generateTimeout(time.Until(end)))

expected := "non-500 status code"
if c.StatusCheckCode > 0 {
if validStatusCodeRange(c.StatusCheckCode) {
expected = fmt.Sprintf("%d status code", c.StatusCheckCode)
}

Expand Down Expand Up @@ -1251,7 +1258,7 @@ func pingServiceURL(serviceURL string, httpClient api.HTTPClient, expectedStatus

// We check for the user's defined status code expectation.
// Otherwise we'll default to checking for a non-500.
if expectedStatusCode > 0 && resp.StatusCode == expectedStatusCode {
if validStatusCodeRange(expectedStatusCode) && resp.StatusCode == expectedStatusCode {
return true, resp.StatusCode, nil
} else if resp.StatusCode < http.StatusInternalServerError {
return true, resp.StatusCode, nil
Expand Down