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
This commit is contained in:
Tanmay Satam 2024-10-22 08:07:14 -04:00 коммит произвёл GitHub
Родитель 32dac80275
Коммит e208003497
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -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())
}
}
}