Skip to content

Commit

Permalink
[build][enhance] error handler for api detach volume
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Jun 1, 2024
1 parent fca772a commit c44d26c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 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 @@ -68,6 +68,7 @@ const (
EcVServerVolumeMigrateProcessingConfirm = ErrorCode("VngCloudVServerVolumeMigrateProcessingConfirm")
EcVServerVolumeMigrateBeingMigrating = ErrorCode("VngCloudVServerVolumeMigrateBeingMigrating")
EcVServerVolumeMigrateInSameZone = ErrorCode("VngCloudVServerVolumeMigrateInSameZone")
EcVServerVolumeIsMigrating = ErrorCode("VngCloudVServerVolumeIsMigrating")
)

// Billing
Expand Down
18 changes: 18 additions & 0 deletions vngcloud/sdk_error/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions vngcloud/services/compute/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit c44d26c

Please sign in to comment.