From e2080034977d6deea16ee9e90470bad9eb11b6b9 Mon Sep 17 00:00:00 2001 From: Tanmay Satam Date: Tue, 22 Oct 2024 08:07:14 -0400 Subject: [PATCH] Use correct error type when handling federated identity credential deletion (#3913) * Use correct error type when handling federated identity credential deletion * Use 'errors.As' instead of type assertion --- pkg/cluster/delete.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/cluster/delete.go b/pkg/cluster/delete.go index 6cee60a24..f55822331 100644 --- a/pkg/cluster/delete.go +++ b/pkg/cluster/delete.go @@ -6,12 +6,14 @@ package cluster import ( "context" "encoding/json" + "errors" "fmt" "net/http" "sort" "strings" "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" mgmtnetwork "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-08-01/network" @@ -425,13 +427,12 @@ func (m *manager) deleteFederatedCredentials(ctx context.Context) error { &armmsi.FederatedIdentityCredentialsClientDeleteOptions{}, ) if err != nil { - cloudErr := err.(*api.CloudError) - - if cloudErr.StatusCode == http.StatusNotFound { - m.log.Errorf("federated identity credentials not found for %s: %v", identity.ResourceID, cloudErr.Error()) + var respErr *azcore.ResponseError + if errors.As(err, &respErr); respErr.StatusCode == http.StatusNotFound { + m.log.Errorf("federated identity credentials not found for %s: %v", identity.ResourceID, err.Error()) continue } else { - return fmt.Errorf("failed to delete federated identity credentials for %s: %v", identity.ResourceID, cloudErr.Error()) + return fmt.Errorf("failed to delete federated identity credentials for %s: %v", identity.ResourceID, err.Error()) } } }