Skip to content

Commit

Permalink
[build][fix] update error handler for secgroup rule
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed May 22, 2024
1 parent 303c46f commit 7e32f36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions vngcloud/sdk_error/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
const (
EcVServerSecgroupRuleNotFound = ErrorCode("VngCloudVServerSecgroupRuleNotFound")
EcVServerSecgroupRuleAlreadyExists = ErrorCode("VngCloudVServerSecgroupRuleAlreadyExists")
EcVServerSecgroupRuleExceedQuota = ErrorCode("VngCloudVServerSecgroupRuleExceedQuota")
)

// VServer network
Expand Down
22 changes: 19 additions & 3 deletions vngcloud/sdk_error/secgroup_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package sdk_error
import lstr "strings"

const (
patternSecgroupRuleNotFound = "cannot get security group rule with id"
patternSecgroupRuleExists = "securitygroupruleexists"
patternSecgroupRuleNotFound = "cannot get security group rule with id"
patternSecgroupRuleExists = "securitygroupruleexists"
patternSecgroupRuleExceedQuota = "exceeded secgroup_rule quota"
)

func WithErrorSecgroupRuleNotFound(perrResp IErrorRespone) func(sdkError ISdkError) {
Expand All @@ -22,7 +23,7 @@ func WithErrorSecgroupRuleNotFound(perrResp IErrorRespone) func(sdkError ISdkErr
}
}

func WithErrorSecgroupAlreadyExists(perrResp IErrorRespone) func(sdkError ISdkError) {
func WithErrorSecgroupRuleAlreadyExists(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
if perrResp == nil {
return
Expand All @@ -36,3 +37,18 @@ func WithErrorSecgroupAlreadyExists(perrResp IErrorRespone) func(sdkError ISdkEr
}
}
}

func WithErrorSecgroupRuleExceedQuota(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
if perrResp == nil {
return
}

errMsg := perrResp.GetMessage()
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternSecgroupRuleExceedQuota) {
sdkError.WithErrorCode(EcVServerSecgroupRuleExceedQuota).
WithMessage(errMsg).
WithErrors(perrResp.GetError())
}
}
}
3 changes: 2 additions & 1 deletion vngcloud/services/network/v2/secgroup_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func (s *NetworkServiceV2) CreateSecgroupRule(popts ICreateSecgroupRuleRequest)
fmt.Println("sdkErr: ", sdkErr)
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorSecgroupNotFound(errResp),
lserr.WithErrorSecgroupAlreadyExists(errResp)).
lserr.WithErrorSecgroupRuleExceedQuota(errResp),
lserr.WithErrorSecgroupRuleAlreadyExists(errResp)).
WithKVparameters("projectId", s.getProjectId())
}

Expand Down

0 comments on commit 7e32f36

Please sign in to comment.