diff --git a/vngcloud/sdk_error/error_codes.go b/vngcloud/sdk_error/error_codes.go index 90cbb02..8fb7c44 100644 --- a/vngcloud/sdk_error/error_codes.go +++ b/vngcloud/sdk_error/error_codes.go @@ -130,6 +130,7 @@ const ( EcVLBListenerNotFound = ErrorCode("VngCloudVLBListenerNotFound") EcVLBMemberMustIdentical = ErrorCode("VngCloudVLBMemberMustIdentical") EcVLBLoadBalancerExceedQuota = ErrorCode("VngCloudVLBLoadBalancerExceedQuota") + EcVLBLoadBalancerIsDeleting = ErrorCode("VngCloudVLBLoadBalancerIsDeleting") ) // Endpoint diff --git a/vngcloud/sdk_error/loadbalancer.go b/vngcloud/sdk_error/loadbalancer.go index b55b4e2..93a735a 100644 --- a/vngcloud/sdk_error/loadbalancer.go +++ b/vngcloud/sdk_error/loadbalancer.go @@ -20,12 +20,14 @@ const ( patternMemberMustIdentical = "the members provided are identical to the existing members in the pool" patternPoolIsUpdating = `pool id [^.]+ is updating` patternLoadBalancerExceedQuota = "exceeded load_balancer quota. current used" + patternLoadBalancerIsDeleting = `load balancer id [^.]+ is deleting` ) var ( - regexErrorLoadBalancerNotReady = lregexp.MustCompile(patternLoadBalancerNotReady) - regexErrorListenerNotReady = lregexp.MustCompile(patternListenerNotReady) - regexErrorPoolIsUpdating = lregexp.MustCompile(patternPoolIsUpdating) + regexErrorLoadBalancerNotReady = lregexp.MustCompile(patternLoadBalancerNotReady) + regexErrorListenerNotReady = lregexp.MustCompile(patternListenerNotReady) + regexErrorPoolIsUpdating = lregexp.MustCompile(patternPoolIsUpdating) + regexErrorLoadBalancerIsDeleting = lregexp.MustCompile(patternLoadBalancerIsDeleting) ) func WithErrorLoadBalancerNotFound(perrResp IErrorRespone) func(sdkError IError) { @@ -168,6 +170,21 @@ func WithErrorLoadBalancerNotReady(perrResp IErrorRespone) func(sdkError IError) } } +func WithErrorLoadBalancerIsDeleting(perrResp IErrorRespone) func(sdkError IError) { + return func(sdkError IError) { + if perrResp == nil { + return + } + + errMsg := lstr.ToLower(lstr.TrimSpace(perrResp.GetMessage())) + if regexErrorLoadBalancerIsDeleting.FindString(errMsg) != "" { + sdkError.WithErrorCode(EcVLBLoadBalancerIsDeleting). + WithMessage(errMsg). + WithErrors(perrResp.GetError()) + } + } +} + func WithErrorListenerNotFound(perrResp IErrorRespone) func(sdkError IError) { return func(sdkError IError) { if perrResp == nil { diff --git a/vngcloud/services/compute/v2/server.go b/vngcloud/services/compute/v2/server.go index 7e67b86..8e7d07f 100644 --- a/vngcloud/services/compute/v2/server.go +++ b/vngcloud/services/compute/v2/server.go @@ -66,7 +66,8 @@ func (s *ComputeServiceV2) DeleteServerById(popts IDeleteServerByIdRequest) lser lserr.WithErrorServerNotFound(errResp), lserr.WithErrorServerDeleteDeletingServer(errResp), lserr.WithErrorServerDeleteBillingServer(errResp), - lserr.WithErrorServerDeleteCreatingServer(errResp)). + lserr.WithErrorServerDeleteCreatingServer(errResp), + lserr.WithErrorVolumeInProcess(errResp)). WithKVparameters("projectId", s.getProjectId(), "serverId", popts.GetServerId()) } diff --git a/vngcloud/services/loadbalancer/v2/loadbalancer.go b/vngcloud/services/loadbalancer/v2/loadbalancer.go index f582a55..7f5b6bd 100644 --- a/vngcloud/services/loadbalancer/v2/loadbalancer.go +++ b/vngcloud/services/loadbalancer/v2/loadbalancer.go @@ -269,7 +269,11 @@ func (s *LoadBalancerServiceV2) DeleteLoadBalancerById(popts IDeleteLoadBalancer if _, sdkErr := s.VLBClient.Delete(url, req); sdkErr != nil { return lserr.SdkErrorHandler(sdkErr, errResp, lserr.WithErrorLoadBalancerNotFound(errResp), - lserr.WithErrorLoadBalancerNotReady(errResp)) + lserr.WithErrorLoadBalancerNotReady(errResp), + lserr.WithErrorLoadBalancerIsDeleting(errResp)). + WithKVparameters( + "loadBalancerId", popts.GetLoadBalancerId(), + "projectId", s.getProjectId()) } return nil