Skip to content

Commit

Permalink
[enhance] enhance error handler for api delete listener
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Nov 21, 2024
1 parent 5782e84 commit 94e93b6
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions vngcloud/sdk_error/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
patternLoadBalancerNotFound2 = "could not find resource"
patternListenerDuplicateName = "duplicated listener name"
patternListenerNotFound = "cannot get listener with id"
patternListenerNotBelongToLoadBalancer = `listener id [^.]+ is not belong to load balancer id [^.]+`
patternListenerDuplicateProtocolOrPort = "duplicated listener protocol port"
patternPoolNotFound = "cannot get pool with id"
patternPoolInUse = "is used in listener"
Expand All @@ -28,12 +29,13 @@ const (
)

var (
regexErrorLoadBalancerNotReady = lregexp.MustCompile(patternLoadBalancerNotReady)
regexErrorListenerNotReady = lregexp.MustCompile(patternListenerNotReady)
regexErrorPoolIsUpdating = lregexp.MustCompile(patternPoolIsUpdating)
regexErrorLoadBalancerIsDeleting = lregexp.MustCompile(patternLoadBalancerIsDeleting)
regexErrorLoadBalancerIsCreating = lregexp.MustCompile(patternLoadBalancerIsCreating)
regexErrorLoadBalancerIsUpdating = lregexp.MustCompile(patternLoadBalancerIsUpdating)
regexErrorLoadBalancerNotReady = lregexp.MustCompile(patternLoadBalancerNotReady)
regexErrorListenerNotReady = lregexp.MustCompile(patternListenerNotReady)
regexErrorPoolIsUpdating = lregexp.MustCompile(patternPoolIsUpdating)
regexErrorLoadBalancerIsDeleting = lregexp.MustCompile(patternLoadBalancerIsDeleting)
regexErrorLoadBalancerIsCreating = lregexp.MustCompile(patternLoadBalancerIsCreating)
regexErrorLoadBalancerIsUpdating = lregexp.MustCompile(patternLoadBalancerIsUpdating)
regexErrorListenerNotBelongToLoadBalancer = lregexp.MustCompile(patternListenerNotBelongToLoadBalancer)
)

func WithErrorLoadBalancerNotFound(perrResp IErrorRespone) func(sdkError IError) {
Expand Down Expand Up @@ -229,7 +231,8 @@ func WithErrorListenerNotFound(perrResp IErrorRespone) func(sdkError IError) {
}

errMsg := perrResp.GetMessage()
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternListenerNotFound) {
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternListenerNotFound) ||
regexErrorListenerNotBelongToLoadBalancer.FindString(errMsg) != "" {
sdkError.WithErrorCode(EcVLBListenerNotFound).
WithMessage(errMsg).
WithErrors(perrResp.GetError())
Expand Down

0 comments on commit 94e93b6

Please sign in to comment.