From 94e93b679ad648e226caab14446a0276a8de46bf Mon Sep 17 00:00:00 2001 From: "Cuong. Duong Manh" Date: Thu, 21 Nov 2024 13:53:29 +0700 Subject: [PATCH] [enhance] enhance error handler for api delete listener --- vngcloud/sdk_error/loadbalancer.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vngcloud/sdk_error/loadbalancer.go b/vngcloud/sdk_error/loadbalancer.go index 3fd943d..c63b3b9 100644 --- a/vngcloud/sdk_error/loadbalancer.go +++ b/vngcloud/sdk_error/loadbalancer.go @@ -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" @@ -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) { @@ -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())