diff --git a/pkg/nsx/services/nsxserviceaccount/cluster.go b/pkg/nsx/services/nsxserviceaccount/cluster.go index 5809f548d..2f12aa50b 100644 --- a/pkg/nsx/services/nsxserviceaccount/cluster.go +++ b/pkg/nsx/services/nsxserviceaccount/cluster.go @@ -196,9 +196,8 @@ func (s *NSXServiceAccountService) RestoreRealizedNSXServiceAccount(ctx context. if err == nil { return fmt.Errorf("CCP store is not synchronized") } - switch err.(type) { - case vapierrors.NotFound: - default: + errortype := err.(*nsxutil.NSXApiError).ErrorTypeEnum + if *errortype != vapierrors.ErrorType_NOT_FOUND { return err } diff --git a/pkg/nsx/util/utils.go b/pkg/nsx/util/utils.go index 7485e1592..bf7eb12a8 100644 --- a/pkg/nsx/util/utils.go +++ b/pkg/nsx/util/utils.go @@ -327,11 +327,13 @@ func DumpHttpRequest(request *http.Request) { type NSXApiError struct { *model.ApiError + *apierrors.ErrorTypeEnum } -func NewNSXApiError(apiError *model.ApiError) *NSXApiError { +func NewNSXApiError(apiError *model.ApiError, errorType *apierrors.ErrorTypeEnum) *NSXApiError { return &NSXApiError{ - ApiError: apiError, + ApiError: apiError, + ErrorTypeEnum: errorType, } } @@ -351,11 +353,11 @@ func TransNSXApiError(err error) error { if err == nil { return err } - apierror, _ := DumpAPIError(err) + apierror, errorType := DumpAPIError(err) if apierror == nil { return err } - return NewNSXApiError(apierror) + return NewNSXApiError(apierror, errorType) } func relatedErrorToString(err *model.RelatedApiError) string {