Skip to content

Commit

Permalink
Add support for error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Sep 28, 2023
1 parent ef30ceb commit 1803e07
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/platformclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,27 @@ func (c *HTTPClient) HTTPGet(path string, successStatus int) ([]byte, error) {
return io.ReadAll(resp.Body)
}

var knownErrorCodes = map[string]string{
"CUSTOMER_CHANNEL_ERROR": `You are attempting to assign a KOTS-enabled customer to a channel with a Helm-only head release. To resolve this, you can either
1. Disable KOTS installations for this customer by passing the --disable-kots flag
2. Assign this customer to a different channel that includes a KOTS-capable release
3. Promote a release containing KOTS manifests to this channel (it will still be installable with the Helm CLI as long as it contains a helm chart)`,
}

func responseBodyToErrorMessage(body []byte) string {
u := map[string]interface{}{}
if err := json.Unmarshal(body, &u); err != nil {
return string(body)
}

if code, ok := u["error_code"].(string); ok && code != "" {
m := knownErrorCodes[code]
if m != "" {
return m
}
}

if m, ok := u["message"].(string); ok && m != "" {
return m
}
Expand Down

0 comments on commit 1803e07

Please sign in to comment.