diff --git a/vngcloud/sdk_error/error_codes.go b/vngcloud/sdk_error/error_codes.go index 9f6084a..f5451ca 100644 --- a/vngcloud/sdk_error/error_codes.go +++ b/vngcloud/sdk_error/error_codes.go @@ -68,6 +68,7 @@ const ( EcVServerVolumeMigrateProcessingConfirm = ErrorCode("VngCloudVServerVolumeMigrateProcessingConfirm") EcVServerVolumeMigrateBeingMigrating = ErrorCode("VngCloudVServerVolumeMigrateBeingMigrating") EcVServerVolumeMigrateInSameZone = ErrorCode("VngCloudVServerVolumeMigrateInSameZone") + EcVServerVolumeIsMigrating = ErrorCode("VngCloudVServerVolumeIsMigrating") ) // Billing diff --git a/vngcloud/sdk_error/volume.go b/vngcloud/sdk_error/volume.go index af53fd0..dc7d96c 100644 --- a/vngcloud/sdk_error/volume.go +++ b/vngcloud/sdk_error/volume.go @@ -25,6 +25,7 @@ const ( // "Cannot get volume type with id vtype-6790f903-38d2-454d-919e-5b49184 patternVolumeMigrateBeingFinish = "this volume cannot migrate difference data because state is confirm final migration" patternVolumeMigrateProcessingConfirm = "this volume cannot initialize migration because state is processing to confirm" patternVolumeMigrateInSameZone = "new volume type must be different zone" + patternVolumeIsMigrating = "is migrating" ) var ( @@ -289,3 +290,20 @@ func WithErrorVolumeMigrateInSameZone(perrResp IErrorRespone) func(sdkError ISdk } } } + +func WithErrorVolumeIsMigrating(perrResp IErrorRespone) func(sdkError ISdkError) { + return func(sdkError ISdkError) { + if perrResp == nil { + return + } + + errMsg := perrResp.GetMessage() + if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternVolumeIsMigrating) { + sdkError.WithErrorCode(EcVServerVolumeIsMigrating). + WithMessage(errMsg). + WithErrors(perrResp.GetError()) + } + } +} + +// patternVolumeIsMigrating diff --git a/vngcloud/services/compute/v2/server.go b/vngcloud/services/compute/v2/server.go index c0b57c8..5eed692 100644 --- a/vngcloud/services/compute/v2/server.go +++ b/vngcloud/services/compute/v2/server.go @@ -130,6 +130,7 @@ func (s *ComputeServiceV2) DetachBlockVolume(popts IDetachBlockVolumeRequest) ls return lserr.SdkErrorHandler(sdkErr, errResp, lserr.WithErrorVolumeNotFound(errResp), lserr.WithErrorVolumeInProcess(errResp), + lserr.WithErrorVolumeIsMigrating(errResp), lserr.WithErrorVolumeAvailable(errResp)). WithKVparameters("projectId", s.getProjectId(), "volumeId", popts.GetBlockVolumeId(),