Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
055c05b
Combined Catch V2 Error with detail and message functions into one
sgagniere Aug 16, 2022
1e4238c
added some new error messages
sgagniere Aug 16, 2022
78a9b48
Cleaned up a line
sgagniere Aug 16, 2022
f3fbaff
Merge branch 'main' of github.com:confluentinc/cli into v2-error-deta…
sgagniere Aug 19, 2022
d8cae1d
Some function renaming
sgagniere Aug 19, 2022
f9a9e9d
Merge branch 'main' of github.com:confluentinc/cli into v2-error-deta…
sgagniere Aug 19, 2022
f7121ff
trim all newlines
sgagniere Aug 19, 2022
e8f31fc
remove unnecessary comments
sgagniere Aug 19, 2022
24f3284
remove empty line
sgagniere Aug 19, 2022
3d00280
switch hardcoded string to resource.User
sgagniere Aug 19, 2022
f142d6c
Rename responseBody to errorResponseBody
sgagniere Aug 19, 2022
a26bc75
Renamed CatchV2 function
sgagniere Aug 19, 2022
4fe17f7
Renamed response body function as well
sgagniere Aug 19, 2022
13918b0
removed hardcoded string
sgagniere Aug 27, 2022
f4b9084
remove another hardcoded string
sgagniere Aug 27, 2022
937e3c7
use backticks for strings w/ quotation marks
sgagniere Aug 29, 2022
86ae976
String style updates
sgagniere Aug 29, 2022
5a35f01
Merge branch 'main' of github.com:confluentinc/cli into v2-error-deta…
sgagniere Aug 29, 2022
f0b8b2f
Removed CatchCCloudV2ErrorResponseBody
sgagniere Aug 29, 2022
0f229ef
Run checks pls
sgagniere Aug 29, 2022
0584cb6
Merge branch 'main' of github.com:confluentinc/cli into v2-error-deta…
sgagniere Aug 30, 2022
37eacbe
Merge branch 'main' of github.com:confluentinc/cli into v2-error-deta…
sgagniere Aug 30, 2022
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
2 changes: 1 addition & 1 deletion internal/cmd/api-key/command_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,5 @@ func (c *command) catchServiceAccountNotValidError(err error, r *http.Response,
return err
}

return errors.CatchV2ErrorDetailWithResponse(err, r)
return errors.CatchCCloudV2Error(err, r)
}
2 changes: 1 addition & 1 deletion internal/cmd/connect/command_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *command) create(cmd *cobra.Command, _ []string) error {

connectorInfo, httpResp, err := c.V2Client.CreateConnector(c.EnvironmentId(), kafkaCluster.ID, connectConfig)
if err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

connectorExpansion, err := c.V2Client.GetConnectorExpansionByName(connectorInfo.GetName(), c.EnvironmentId(), kafkaCluster.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/connect/command_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *command) update(cmd *cobra.Command, args []string) error {
}

if _, httpResp, err := c.V2Client.CreateOrUpdateConnectorConfig(connectorExpansion.Info.GetName(), c.EnvironmentId(), kafkaCluster.ID, *userConfigs); err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

utils.Printf(cmd, errors.UpdatedResourceMsg, resource.Connector, args[0])
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_pool_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *identityPoolCommand) create(cmd *cobra.Command, args []string) error {
}
resp, httpResp, err := c.V2Client.CreateIdentityPool(createIdentityPool, provider)
if err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

identityPool := &identityPool{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_pool_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *identityPoolCommand) delete(cmd *cobra.Command, args []string) error {
}

if httpResp, err := c.V2Client.DeleteIdentityPool(args[0], provider); err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

utils.ErrPrintf(cmd, errors.DeletedResourceMsg, resource.IdentityPool, args[0])
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_pool_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c identityPoolCommand) describe(cmd *cobra.Command, args []string) error {

identityPoolProfile, httpResp, err := c.V2Client.GetIdentityPool(args[0], provider)
if err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

describeIdentityPool := &identityPool{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_pool_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *identityPoolCommand) update(cmd *cobra.Command, args []string) error {

resp, httpResp, err := c.V2Client.UpdateIdentityPool(updateIdentityPool, provider)
if err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

describeIdentityPool := &identityPool{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_provider_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *identityProviderCommand) create(cmd *cobra.Command, args []string) erro
}
resp, httpResp, err := c.V2Client.CreateIdentityProvider(newIdentityProvider)
if err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

identityProvider := &identityProvider{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_provider_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *identityProviderCommand) newDeleteCommand() *cobra.Command {

func (c *identityProviderCommand) delete(cmd *cobra.Command, args []string) error {
if httpResp, err := c.V2Client.DeleteIdentityProvider(args[0]); err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

utils.ErrPrintf(cmd, errors.DeletedResourceMsg, resource.IdentityProvider, args[0])
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_provider_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c identityProviderCommand) newDescribeCommand() *cobra.Command {
func (c identityProviderCommand) describe(cmd *cobra.Command, args []string) error {
identityProviderProfile, httpResp, err := c.V2Client.GetIdentityProvider(args[0])
if err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

describeIdentityProvider := &identityProvider{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_provider_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *identityProviderCommand) update(cmd *cobra.Command, args []string) erro

resp, httpResp, err := c.V2Client.UpdateIdentityProvider(update)
if err != nil {
return errors.CatchV2ErrorMessageWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

describeIdentityProvider := &identityProvider{
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_service_account_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *serviceAccountCommand) delete(cmd *cobra.Command, args []string) error

httpResp, err := c.V2Client.DeleteIamServiceAccount(args[0])
if err != nil {
return errors.Errorf(`failed to delete service account "%s": %v`, args[0], errors.CatchV2ErrorDetailWithResponse(err, httpResp))
return errors.Errorf(errors.DeleteResourceErrorMsg, resource.ServiceAccount, args[0], errors.CatchCCloudV2Error(err, httpResp))
}

utils.ErrPrintf(cmd, errors.DeletedResourceMsg, resource.ServiceAccount, args[0])
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_user_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c userCommand) delete(cmd *cobra.Command, args []string) error {

httpResp, err := c.V2Client.DeleteIamUser(resourceId)
if err != nil {
return errors.Errorf(`failed to delete user "%s": %v`, resourceId, errors.CatchV2ErrorDetailWithResponse(err, httpResp))
return errors.Errorf(errors.DeleteResourceErrorMsg, resource.User, resourceId, errors.CatchCCloudV2Error(err, httpResp))
}

utils.Printf(cmd, errors.DeletedResourceMsg, resource.User, resourceId)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/iam/command_user_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *userCommand) update(cmd *cobra.Command, args []string) error {

_, httpResp, err := c.V2Client.UpdateIamUser(resourceId, update)
if err != nil {
return errors.Errorf(`failed to update user "%s": %v`, resourceId, errors.CatchV2ErrorDetailWithResponse(err, httpResp))
return errors.Errorf(errors.UpdateResourceErrorMsg, resource.User, resourceId, errors.CatchCCloudV2Error(err, httpResp))
}

utils.ErrPrintf(cmd, errors.UpdateSuccessMsg, "full name", "user", resourceId, fullName)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/kafka/command_cluster_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *clusterCommand) update(cmd *cobra.Command, args []string, prompt form.P

updatedCluster, httpResp, err := c.V2Client.UpdateKafkaCluster(clusterID, update)
if err != nil {
return errors.NewWrapErrorWithSuggestions(errors.CatchV2ErrorDetailWithResponse(err, httpResp), "failed to update Kafka cluster", errors.KafkaClusterUpdateFailedSuggestions)
return errors.NewWrapErrorWithSuggestions(errors.CatchCCloudV2Error(err, httpResp), "failed to update Kafka cluster", errors.KafkaClusterUpdateFailedSuggestions)
}

return c.outputKafkaClusterDescription(cmd, &updatedCluster)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/stream-share/command_consumer_redeem.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *command) redeemShare(cmd *cobra.Command, args []string) error {

redeemResponse, httpResp, err := c.V2Client.RedeemSharedToken(token, awsAccountId, azureSubscriptionId)
if err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

var resources []string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *command) deleteConsumerShare(cmd *cobra.Command, args []string) error {
shareId := args[0]

if httpResp, err := c.V2Client.DeleteConsumerShare(shareId); err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

utils.Printf(cmd, errors.DeletedResourceMsg, resource.ConsumerShare, shareId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *command) describeConsumerShare(cmd *cobra.Command, args []string) error

consumerShare, httpResp, err := c.V2Client.DescribeConsumerShare(shareId)
if err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

return output.DescribeObject(cmd, c.buildConsumerShare(consumerShare), consumerShareListFields, consumerHumanLabelMap, consumerStructuredLabelMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *command) createEmailInvite(cmd *cobra.Command, _ []string) error {

invite, httpResp, err := c.V2Client.CreateInvite(environment, kafkaCluster, topic, email)
if err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

return output.DescribeObject(cmd, c.buildProviderShare(invite), providerShareListFields, providerHumanLabelMap, providerStructuredLabelMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *command) resendEmailInvite(cmd *cobra.Command, args []string) error {
shareId := args[0]

if httpResp, err := c.V2Client.ResendInvite(shareId); err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

utils.Printf(cmd, errors.ResendInviteMsg, shareId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *command) deleteProviderShare(cmd *cobra.Command, args []string) error {
shareId := args[0]

if httpResp, err := c.V2Client.DeleteProviderShare(shareId); err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

utils.Printf(cmd, errors.DeletedResourceMsg, resource.ProviderShare, shareId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *command) describeProviderShare(cmd *cobra.Command, args []string) error

provideShare, httpResp, err := c.V2Client.DescribeProviderShare(shareId)
if err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}

return output.DescribeObject(cmd, c.buildProviderShare(provideShare), providerShareListFields, providerHumanLabelMap, providerStructuredLabelMap)
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/auth/sso/auth_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ func (s *authState) getOAuthTokenResponse(payload *strings.Reader) (map[string]i
return nil, errors.Wrap(err, "failed to get oauth token")
}
defer res.Body.Close()
responseBody, _ := ioutil.ReadAll(res.Body)
errorResponseBody, _ := ioutil.ReadAll(res.Body)
var data map[string]interface{}
err = json.Unmarshal(responseBody, &data)
err = json.Unmarshal(errorResponseBody, &data)
if err != nil {
log.CliLogger.Debugf("Failed oauth token response body: %s", responseBody)
log.CliLogger.Debugf("Failed oauth token response body: %s", errorResponseBody)
return nil, errors.Wrap(err, errors.UnmarshalOAuthTokenErrorMsg)
}
return data, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/ccloudv2/cdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *Client) ListProviderShares(sharedResource string) ([]cdxv1.CdxV1Provide
for !done {
page, r, err := c.executeListProviderShares(sharedResource, pageToken)
if err != nil {
return nil, errors.CatchV2ErrorDetailWithResponse(err, r)
return nil, errors.CatchCCloudV2Error(err, r)
}
list = append(list, page.GetData()...)

Expand All @@ -96,7 +96,7 @@ func (c *Client) ListConsumerShares(sharedResource string) ([]cdxv1.CdxV1Consume
for !done {
page, r, err := c.executeListConsumerShares(sharedResource, pageToken)
if err != nil {
return nil, errors.CatchV2ErrorDetailWithResponse(err, r)
return nil, errors.CatchCCloudV2Error(err, r)
}
list = append(list, page.GetData()...)

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/dynamic-config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (d *DynamicContext) FetchCluster(clusterId string) (*v1.KafkaClusterConfig,

cluster, httpResp, err := d.V2Client.DescribeKafkaCluster(clusterId, environmentId)
if err != nil {
return nil, errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return nil, errors.CatchCCloudV2Error(err, httpResp)
}

apiEndpoint, err := getKafkaApiEndpoint(d.Client, clusterId, environmentId)
Expand Down Expand Up @@ -60,7 +60,7 @@ func (d *DynamicContext) FetchAPIKeyError(apiKey string, clusterID string) error
// check if this is API key exists server-side
key, httpResp, err := d.V2Client.GetApiKey(apiKey)
if err != nil {
return errors.CatchV2ErrorDetailWithResponse(err, httpResp)
return errors.CatchCCloudV2Error(err, httpResp)
}
// check if the key is for the right cluster
ok := key.Spec.Resource.Id == clusterID
Expand Down
68 changes: 26 additions & 42 deletions internal/pkg/errors/catcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const quotaExceededRegex = ".* is currently limited to .*"

type responseBody struct {
type errorResponseBody struct {
Error []errorDetail `json:"errors"`
Message string `json:"message"`
}
Expand Down Expand Up @@ -141,26 +141,30 @@ func catchCCloudBackendUnmarshallingError(err error) error {
CCLOUD-SDK-GO CLIENT ERROR CATCHING
*/

func CatchV2ErrorDetailWithResponse(err error, r *http.Response) error {
func CatchCCloudV2Error(err error, r *http.Response) error {
if err == nil {
return nil
}

if r == nil {
return err
}

body, _ := io.ReadAll(r.Body)
return CatchV2ErrorDetailWithResponseBody(err, body)
}

func CatchV2ErrorDetailWithResponseBody(err error, body []byte) error {
var resBody responseBody
var resBody errorResponseBody
_ = json.Unmarshal(body, &resBody)
if len(resBody.Error) > 0 {
detail := resBody.Error[0].Detail
if ok, _ := regexp.MatchString(quotaExceededRegex, detail); ok {
return NewWrapErrorWithSuggestions(err, detail, QuotaExceededSuggestions)
Comment on lines 158 to 159

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan that this is hardcoded here... this only applies to one service so it's wasteful to always check for it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which service? There are a few other specialized catchers in this file, maybe we can make a specialized one for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... this probably needs an updating. I just took a look at some of the quotas by listing them on the CLI. Tried to create 11 environments and hit a quote error that matches quotaExceededRegex, but didn't get the suggestion.

So this hard-coding only prints that suggestion on whatever subset of commands uses (what is now) CatchCCloudV2Error, which is sub-optimal.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it would be great if we could only wrap the quota service functions with this catcher

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be deserving of a separate pr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make that my next cleanup task. I'm assuming only create and update subcommands can hit these quota errors.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might introduce a new subcommand that also returns that error, so in my opinion the safest thing to do here would be to wrap every function in service_quota.go with a function that iterates through a list of error catchers and applies them one by one. As of right now, that list would just contain errors.CatchCCloudV2Error() and this one.

Copy link
Contributor

@MuweiHe MuweiHe Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New v2 requests to create a resource could result in this (429 if i remember correctly?). Environment won't have this because it was still using v1 to create.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I didn't realize environment was using v1.

} else if detail != "" {
return Wrap(err, strings.TrimSuffix(resBody.Error[0].Detail, "\n"))
return Wrap(err, strings.TrimSuffix(detail, "\n"))
}
}
if resBody.Message != "" {
return Wrap(err, strings.TrimRight(resBody.Message, "\n"))
}

return err
}

Expand All @@ -184,10 +188,10 @@ func CatchEnvironmentNotFoundError(err error, r *http.Response) error {
}

if r != nil && r.StatusCode == http.StatusForbidden {
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), "environment not found or access forbidden", EnvNotFoundSuggestions)
return NewWrapErrorWithSuggestions(CatchCCloudV2Error(err, r), "environment not found or access forbidden", EnvNotFoundSuggestions)
}

return CatchV2ErrorDetailWithResponse(err, r)
return CatchCCloudV2Error(err, r)
}

func CatchKafkaNotFoundError(err error, clusterId string, r *http.Response) error {
Expand All @@ -203,10 +207,10 @@ func CatchKafkaNotFoundError(err error, clusterId string, r *http.Response) erro
if r.Request.Method == http.MethodDelete {
suggestions = KafkaClusterDeletingSuggestions
}
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), "Kafka cluster not found or access forbidden", suggestions)
return NewWrapErrorWithSuggestions(CatchCCloudV2Error(err, r), "Kafka cluster not found or access forbidden", suggestions)
}

return CatchV2ErrorDetailWithResponse(err, r)
return CatchCCloudV2Error(err, r)
}

func CatchClusterConfigurationNotValidError(err error, r *http.Response) error {
Expand All @@ -218,19 +222,19 @@ func CatchClusterConfigurationNotValidError(err error, r *http.Response) error {
return err
}

body, _ := io.ReadAll(r.Body)
if strings.Contains(string(body), "CKU must be greater") {
err = CatchCCloudV2Error(err, r)
if strings.Contains(err.Error(), "CKU must be greater") {
return New(InvalidCkuErrorMsg)
}

return CatchV2ErrorDetailWithResponseBody(err, body)
return err
}

func CatchApiKeyForbiddenAccessError(err error, operation string, r *http.Response) error {
if r != nil && r.StatusCode == http.StatusForbidden || strings.Contains(err.Error(), "Unknown API key") {
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), fmt.Sprintf("error %s API key", operation), APIKeyNotFoundSuggestions)
return NewWrapErrorWithSuggestions(CatchCCloudV2Error(err, r), fmt.Sprintf("error %s API key", operation), APIKeyNotFoundSuggestions)
}
return CatchV2ErrorDetailWithResponse(err, r)
return CatchCCloudV2Error(err, r)
}

func CatchKSQLNotFoundError(err error, clusterId string) error {
Expand All @@ -253,13 +257,13 @@ func CatchServiceNameInUseError(err error, r *http.Response, serviceName string)
return err
}

body, _ := io.ReadAll(r.Body)
if strings.Contains(string(body), "Service name is already in use") {
err = CatchCCloudV2Error(err, r)
if strings.Contains(err.Error(), "Service name is already in use") {
errorMsg := fmt.Sprintf(ServiceNameInUseErrorMsg, serviceName)
return NewErrorWithSuggestions(errorMsg, ServiceNameInUseSuggestions)
}

return CatchV2ErrorDetailWithResponseBody(err, body)
return err
}

func CatchServiceAccountNotFoundError(err error, r *http.Response, serviceAccountId string) error {
Expand All @@ -273,31 +277,11 @@ func CatchServiceAccountNotFoundError(err error, r *http.Response, serviceAccoun
errorMsg := fmt.Sprintf(ServiceAccountNotFoundErrorMsg, serviceAccountId)
return NewErrorWithSuggestions(errorMsg, ServiceAccountNotFoundSuggestions)
case http.StatusForbidden:
return NewWrapErrorWithSuggestions(CatchV2ErrorDetailWithResponse(err, r), "service account not found or access forbidden", ServiceAccountNotFoundSuggestions)
return NewWrapErrorWithSuggestions(CatchCCloudV2Error(err, r), "service account not found or access forbidden", ServiceAccountNotFoundSuggestions)
}
}

return CatchV2ErrorDetailWithResponse(err, r)
}

func CatchV2ErrorMessageWithResponse(err error, r *http.Response) error {
if err == nil {
return nil
}

if r == nil {
return err
}
body, _ := io.ReadAll(r.Body)
var resBody responseBody
_ = json.Unmarshal(body, &resBody)
if resBody.Message != "" {
// {"error_code":400,"message":"Connector configuration is invalid and contains 1 validation error(s).
// Errors: quickstart: Value \"CLICKM\" is not a valid \"Select a template\" type\n"}
return Wrap(err, strings.TrimSuffix(resBody.Message, "\n"))
}

return err
return CatchCCloudV2Error(err, r)
}

func isResourceNotFoundError(err error) bool {
Expand Down
Loading