Skip to content

Commit

Permalink
[chore] enhance error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Oct 28, 2024
1 parent ae26495 commit 54382fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions vngcloud/sdk_error/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const (
EcVLBLoadBalancerExceedQuota = ErrorCode("VngCloudVLBLoadBalancerExceedQuota")
EcVLBLoadBalancerIsDeleting = ErrorCode("VngCloudVLBLoadBalancerIsDeleting")
EcVLBLoadBalancerIsCreating = ErrorCode("VngCloudVLBLoadBalancerIsCreating")
EcVLBLoadBalancerIsUpdating = ErrorCode("VngCloudVLBLoadBalancerIsUpdating")
EcVLBLoadBalancerResizeSamePackage = ErrorCode("VngCloudVLBLoadBalancerResizeSamePackage")
EcVLBLoadBalancerPackageNotFound = ErrorCode("VngCloudVLBLoadBalancerPackageNotFound")
)
Expand Down
20 changes: 19 additions & 1 deletion vngcloud/sdk_error/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
patternLoadBalancerIsCreating = `load balancer id [^.]+ is creating`
patternLoadBalancerResizeSamePackage = "is the same as the current package"
patternLoadbalancerPackageNotFound = "invalid package id"
patternLoadBalancerIsUpdating = `load balancer id [^.]+ is updating`
)

var (
Expand All @@ -32,6 +33,7 @@ var (
regexErrorPoolIsUpdating = lregexp.MustCompile(patternPoolIsUpdating)
regexErrorLoadBalancerIsDeleting = lregexp.MustCompile(patternLoadBalancerIsDeleting)
regexErrorLoadBalancerIsCreating = lregexp.MustCompile(patternLoadBalancerIsCreating)
regexErrorLoadBalancerIsUpdating = lregexp.MustCompile(patternLoadBalancerIsUpdating)
)

func WithErrorLoadBalancerNotFound(perrResp IErrorRespone) func(sdkError IError) {
Expand Down Expand Up @@ -166,7 +168,8 @@ func WithErrorLoadBalancerNotReady(perrResp IErrorRespone) func(sdkError IError)
errMsg := lstr.ToLower(lstr.TrimSpace(perrResp.GetMessage()))
if regexErrorLoadBalancerNotReady.FindString(errMsg) != "" ||
regexErrorListenerNotReady.FindString(errMsg) != "" ||
regexErrorPoolIsUpdating.FindString(errMsg) != "" {
regexErrorPoolIsUpdating.FindString(errMsg) != "" ||
regexErrorLoadBalancerIsUpdating.FindString(errMsg) != "" {
sdkError.WithErrorCode(EcVLBLoadBalancerNotReady).
WithMessage(errMsg).
WithErrors(perrResp.GetError())
Expand Down Expand Up @@ -204,6 +207,21 @@ func WithErrorLoadBalancerIsCreating(perrResp IErrorRespone) func(sdkError IErro
}
}

func WithErrorLoadBalancerIsUpdating(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}

errMsg := lstr.ToLower(lstr.TrimSpace(perrResp.GetMessage()))
if regexErrorLoadBalancerIsUpdating.FindString(errMsg) != "" {
sdkError.WithErrorCode(EcVLBLoadBalancerIsUpdating).
WithMessage(errMsg).
WithErrors(perrResp.GetError())
}
}
}

func WithErrorListenerNotFound(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
Expand Down

0 comments on commit 54382fd

Please sign in to comment.