Skip to content

Commit

Permalink
PLT-827: Unwrap error type cast correction.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern committed Nov 22, 2023
1 parent a5d9a3b commit 4f53362
Show file tree
Hide file tree
Showing 31 changed files with 160 additions and 50 deletions.
7 changes: 5 additions & 2 deletions client/account_aws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)
Expand Down Expand Up @@ -71,8 +73,9 @@ func (h *V1Client) GetCloudAccountAws(uid, AccountContext string) (*models.V1Aws
params = clusterC.NewV1CloudAccountsAwsGetParams().WithUID(uid)
}
success, err := client.V1CloudAccountsAwsGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion client/account_azure.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -70,7 +72,9 @@ func (h *V1Client) GetCloudAccountAzure(uid, AccountContext string) (*models.V1A
params = clusterC.NewV1CloudAccountsAzureGetParams().WithUID(uid)
}
success, err := client.V1CloudAccountsAzureGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
7 changes: 5 additions & 2 deletions client/account_coxedge.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)
Expand Down Expand Up @@ -71,8 +73,9 @@ func (h *V1Client) GetCloudAccountCoxEdge(uid, AccountContext string) (*models.V
}

success, err := client.V1CloudAccountsCoxEdgeGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion client/account_gcp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -73,7 +75,9 @@ func (h *V1Client) GetCloudAccountGcp(uid, AccountContext string) (*models.V1Gcp
}

success, err := client.V1CloudAccountsGcpGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion client/account_maas.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -115,7 +117,9 @@ func (h *V1Client) GetCloudAccountMaas(uid, AccountContext string) (*models.V1Ma
}

success, err := client.V1CloudAccountsMaasGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion client/account_openstack.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -114,7 +116,9 @@ func (h *V1Client) GetCloudAccountOpenStack(uid, AccountContext string) (*models
}

success, err := client.V1CloudAccountsOpenStackGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion client/account_tke.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -73,7 +75,9 @@ func (h *V1Client) GetCloudAccountTke(uid, AccountContext string) (*models.V1Ten
}

success, err := client.V1CloudAccountsTencentGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
8 changes: 6 additions & 2 deletions client/account_vsphere.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)
Expand Down Expand Up @@ -120,7 +122,9 @@ func (h *V1Client) GetCloudAccountVsphere(uid, AccountContext string) (*models.V
}

success, err := client.V1CloudAccountsVsphereGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
11 changes: 9 additions & 2 deletions client/application.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1"
"github.com/spectrocloud/hapi/models"
Expand All @@ -18,7 +20,9 @@ func (h *V1Client) GetApplication(uid string) (*models.V1AppDeployment, error) {

params := v1.NewV1AppDeploymentsUIDGetParamsWithContext(h.Ctx).WithUID(uid)
success, err := client.V1AppDeploymentsUIDGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down Expand Up @@ -48,11 +52,14 @@ func (h *V1Client) SearchAppDeploymentSummaries(scope string, filter *models.V1A
}

resp, err := client.V1DashboardAppDeployments(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
}

return resp.Payload.AppDeployments, nil
}

Expand Down
16 changes: 12 additions & 4 deletions client/application_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
hashboardC "github.com/spectrocloud/hapi/hashboard/client/v1"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"

"github.com/spectrocloud/palette-sdk-go/client/herr"
)

Expand Down Expand Up @@ -72,7 +73,9 @@ func (h *V1Client) GetApplicationProfileTiers(applicationProfileUID string) ([]*

params := clusterC.NewV1AppProfilesUIDTiersGetParamsWithContext(h.Ctx).WithUID(applicationProfileUID)
success, err := client.V1AppProfilesUIDTiersGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand All @@ -97,11 +100,14 @@ func (h *V1Client) GetApplicationProfileTierManifestContent(applicationProfileUI
Context: h.Ctx,
}
success, err := client.V1AppProfilesUIDTiersUIDManifestsUIDGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return "", nil
} else if err != nil {
return "", err
}

return success.Payload.Spec.Published.Content, nil
}

Expand Down Expand Up @@ -129,7 +135,8 @@ func (h *V1Client) SearchAppProfileSummaries(scope string, filter *models.V1AppP
params.Offset = &resp.Payload.Listmeta.Offset
}
resp, err = client.V1DashboardAppProfiles(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down Expand Up @@ -197,7 +204,8 @@ func (h *V1Client) UpdateApplicationProfileTiers(appProfileUID, tierUID string,
}

_, err = client.V1AppProfilesUIDTiersUIDUpdate(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil
} else if err != nil {
return err
Expand Down
14 changes: 11 additions & 3 deletions client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ func (h *V1Client) SearchClusterSummaries(clusterContext string, filter *models.
}

resp, err := client.V1SpectroClustersSearchFilterSummary(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
}

return resp.Payload.Items, nil
}

Expand All @@ -118,11 +120,14 @@ func (h *V1Client) listClusters(clusterContext string) ([]*models.V1SpectroClust
var limit int64 = 0
params.Limit = &limit
resp, err := client.V1SpectroClustersList(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
}

return resp.Payload.Items, nil
}

Expand All @@ -140,11 +145,14 @@ func (h *V1Client) listClustersMetadata(clusterContext string) ([]*models.V1Obje
params = hashboardC.NewV1SpectroClustersMetadataParams()
}
resp, err := client.V1SpectroClustersMetadata(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
}

return resp.Payload.Items, nil
}

Expand Down
4 changes: 3 additions & 1 deletion client/cluster_aks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"errors"
"time"

"github.com/spectrocloud/hapi/apiutil/transport"
Expand Down Expand Up @@ -105,7 +106,8 @@ func (h *V1Client) GetCloudConfigAks(configUID, ClusterContext string) (*models.
}

success, err := client.V1CloudConfigsAksGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
7 changes: 5 additions & 2 deletions client/cluster_aws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package client

import (
hapitransport "github.com/spectrocloud/hapi/apiutil/transport"
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)
Expand Down Expand Up @@ -101,7 +103,8 @@ func (h *V1Client) GetCloudConfigAws(configUID, ClusterContext string) (*models.
}

success, err := client.V1CloudConfigsAwsGet(params)
if e, ok := err.(*hapitransport.TransportError); ok && e.HttpCode == 404 {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion client/cluster_azure.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -103,7 +105,9 @@ func (h *V1Client) GetCloudConfigAzure(configUID, ClusterContext string) (*model
}

success, err := client.V1CloudConfigsAzureGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {

var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion client/cluster_coxedge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"errors"

"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
Expand Down Expand Up @@ -103,7 +105,8 @@ func (h *V1Client) GetCloudConfigCoxEdge(configUID, ClusterContext string) (*mod
}

success, err := client.V1CloudConfigsCoxEdgeGet(params)
if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 {
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 4f53362

Please sign in to comment.