diff --git a/vngcloud/sdk_error/error_codes.go b/vngcloud/sdk_error/error_codes.go index 0dbf603..035a892 100644 --- a/vngcloud/sdk_error/error_codes.go +++ b/vngcloud/sdk_error/error_codes.go @@ -36,6 +36,7 @@ const ( const ( EcVServerSecgroupRuleNotFound = ErrorCode("VngCloudVServerSecgroupRuleNotFound") EcVServerSecgroupRuleAlreadyExists = ErrorCode("VngCloudVServerSecgroupRuleAlreadyExists") + EcVServerSecgroupRuleExceedQuota = ErrorCode("VngCloudVServerSecgroupRuleExceedQuota") ) // VServer network diff --git a/vngcloud/sdk_error/secgroup_rule.go b/vngcloud/sdk_error/secgroup_rule.go index da49974..4fa33e0 100644 --- a/vngcloud/sdk_error/secgroup_rule.go +++ b/vngcloud/sdk_error/secgroup_rule.go @@ -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) { @@ -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 @@ -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()) + } + } +} diff --git a/vngcloud/services/network/v2/secgroup_rule.go b/vngcloud/services/network/v2/secgroup_rule.go index 2319236..fa71db1 100644 --- a/vngcloud/services/network/v2/secgroup_rule.go +++ b/vngcloud/services/network/v2/secgroup_rule.go @@ -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()) }