diff --git a/vngcloud/sdk_error/error_codes.go b/vngcloud/sdk_error/error_codes.go index d50479a..bc1955a 100644 --- a/vngcloud/sdk_error/error_codes.go +++ b/vngcloud/sdk_error/error_codes.go @@ -112,6 +112,7 @@ const ( const ( EcVServerVirtualAddressNotFound = ErrorCode("VngCloudVServerVirtualAddressNotFound") EcVServerVirtualAddressExceedQuota = ErrorCode("VngCloudVServerVirtualAddressExceedQuota") + EcVServerVirtualAddressInUse = ErrorCode("VngCloudVServerVirtualAddressInUse") ) // vServer quota diff --git a/vngcloud/sdk_error/virtualaddress.go b/vngcloud/sdk_error/virtualaddress.go index 078f30b..3327029 100644 --- a/vngcloud/sdk_error/virtualaddress.go +++ b/vngcloud/sdk_error/virtualaddress.go @@ -9,6 +9,7 @@ const ( patternVirtualAddressNotFound = `virtual ip address with id [^.]+ is not found` patternAddressPairNotFound = `address pair with uuid: [^.]+ was not existing` patternVirtualAddressExceedQuota = "exceeded virtual_ip_address quota" + patternVirtualAddressInUse = "ip address is already in use" ) var ( @@ -60,4 +61,20 @@ func WithErrorVirtualAddressExceedQuota(perrResp IErrorRespone) func(sdkError IE WithErrorCategories(ErrCatQuota) } } -} \ No newline at end of file +} + +func WithErrorVirtualAddressInUse(perrResp IErrorRespone) func(sdkError IError) { + return func(sdkError IError) { + if perrResp == nil { + return + } + + errMsg := perrResp.GetMessage() + if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternVirtualAddressInUse) { + sdkError.WithErrorCode(EcVServerVirtualAddressInUse). + WithMessage(errMsg). + WithErrors(perrResp.GetError()). + WithErrorCategories(ErrCatQuota) + } + } +} diff --git a/vngcloud/services/network/v2/virtualaddress.go b/vngcloud/services/network/v2/virtualaddress.go index ab2324c..7805448 100644 --- a/vngcloud/services/network/v2/virtualaddress.go +++ b/vngcloud/services/network/v2/virtualaddress.go @@ -38,7 +38,8 @@ func (s *NetworkServiceV2) DeleteVirtualAddressById(popts IDeleteVirtualAddressB if _, sdkErr := s.VserverClient.Delete(url, req); sdkErr != nil { return lserr.SdkErrorHandler(sdkErr, errResp, - lserr.WithErrorVirtualAddressNotFound(errResp)). + lserr.WithErrorVirtualAddressNotFound(errResp), + lserr.WithErrorVirtualAddressInUse(errResp)). WithKVparameters(popts.ToMap()). WithErrorCategories(lserr.ErrCatVServer, lserr.ErrCatVirtualAddress) }