diff --git a/vngcloud/sdk_error/common.go b/vngcloud/sdk_error/common.go index 7b76624..4b63711 100644 --- a/vngcloud/sdk_error/common.go +++ b/vngcloud/sdk_error/common.go @@ -10,6 +10,7 @@ import ( const ( patternOutOfPoc = "you do not have sufficient credits to complete the purchase" patternPagingInvalid = "page or size invalid" + patternTagKeyInvalid = "the value for the tag key contains illegal characters" ) func ErrorHandler(perr error, popts ...func(psdkErr IError)) IError { @@ -95,6 +96,21 @@ func WithErrorOutOfPoc(perrResp IErrorRespone) func(sdkError IError) { } } +func WithErrorTagKeyInvalid(perrResp IErrorRespone) func(sdkError IError) { + return func(sdkError IError) { + if perrResp == nil { + return + } + + errMsg := perrResp.GetMessage() + if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternTagKeyInvalid) { + sdkError.WithErrorCode(EcTagKeyInvalid). + WithMessage(errMsg). + WithErrors(perrResp.GetError()) + } + } +} + func WithErrorPagingInvalid(perrResp IErrorRespone) func(sdkError IError) { return func(sdkError IError) { if perrResp == nil { diff --git a/vngcloud/sdk_error/error_codes.go b/vngcloud/sdk_error/error_codes.go index 8649abc..c614175 100644 --- a/vngcloud/sdk_error/error_codes.go +++ b/vngcloud/sdk_error/error_codes.go @@ -8,6 +8,7 @@ const ( EcInternalServerError = ErrorCode("VngCloudApiInternalServerError") EcServiceMaintenance = ErrorCode("VngCloudServiceMaintenance") EcPagingInvalid = ErrorCode("VngCloudApiPagingInvalid") + EcTagKeyInvalid = ErrorCode("VngCloudApiTagKeyInvalid") EcPermissionDenied = ErrorCode("VngCloudApiPermissionDenied") EcUnexpectedError = ErrorCode("VngCloudApiUnexpectedError") ) diff --git a/vngcloud/services/loadbalancer/v2/irequest.go b/vngcloud/services/loadbalancer/v2/irequest.go index ab54624..42c4949 100644 --- a/vngcloud/services/loadbalancer/v2/irequest.go +++ b/vngcloud/services/loadbalancer/v2/irequest.go @@ -142,4 +142,5 @@ type IUpdateTagsRequest interface { ToRequestBody(plstTags *lsentity.ListTags) interface{} ParseUserAgent() string WithTags(ptags ...string) IUpdateTagsRequest + ToMap() map[string]interface{} } diff --git a/vngcloud/services/loadbalancer/v2/tag.go b/vngcloud/services/loadbalancer/v2/tag.go index 5b7f524..fe1834f 100644 --- a/vngcloud/services/loadbalancer/v2/tag.go +++ b/vngcloud/services/loadbalancer/v2/tag.go @@ -62,7 +62,8 @@ func (s *LoadBalancerServiceV2) UpdateTags(popts IUpdateTagsRequest) lserr.IErro WithJsonError(errResp) if _, sdkErr = s.VServerClient.Put(url, req); sdkErr != nil { - return lserr.SdkErrorHandler(sdkErr, errResp) + return lserr.SdkErrorHandler(sdkErr, errResp, + lserr.WithErrorTagKeyInvalid(errResp)).WithParameters(popts.ToMap()) } return nil diff --git a/vngcloud/services/loadbalancer/v2/tag_request.go b/vngcloud/services/loadbalancer/v2/tag_request.go index 6a43ffa..1e026d5 100644 --- a/vngcloud/services/loadbalancer/v2/tag_request.go +++ b/vngcloud/services/loadbalancer/v2/tag_request.go @@ -102,3 +102,11 @@ func (s *UpdateTagsRequest) WithTags(ptags ...string) IUpdateTagsRequest { return s } + +func (s *UpdateTagsRequest) ToMap() map[string]interface{} { + res := make(map[string]interface{}) + for _, tag := range s.TagRequestList { + res[tag.Key] = tag.Value + } + return res +}