Skip to content

Commit

Permalink
[feat] update error handler for api update secgroup for server
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Jun 7, 2024
1 parent c44d26c commit cbdb64d
Show file tree
Hide file tree
Showing 3 changed files with 18 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 @@ -81,6 +81,7 @@ const (
const (
EcVServerServerNotFound = ErrorCode("VngCloudVServerServerNotFound")
EcVServerServerDeleteCreatingServer = ErrorCode("VngCloudVServerServerDeleteCreatingServer")
EcVServerServerExpired = ErrorCode("VngCloudVServerServerExpired")
EcVServerServerExceedQuota = ErrorCode("VngCloudVServerServerExceedQuota")
EcVServerServerDeleteDeletingServer = ErrorCode("VngCloudVServerServerDeleteDeletingServer")
EcVServerServerDeleteBillingServer = ErrorCode("VngCloudVServerServerDeleteBillingServer")
Expand Down
16 changes: 16 additions & 0 deletions vngcloud/sdk_error/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
patternBillingPaymentMethodNotAllowed = "payment method is not allowed for the user"
patternServerAttachVolumeQuotaExceeded = "exceeded volume_per_server quota"
patternServerAttachEncryptedVolume = "cannot attach encryption volume"
patternServerExpired = "server is expired"
)

func WithErrorServerNotFound(perrResp IErrorRespone) func(sdkError ISdkError) {
Expand Down Expand Up @@ -43,6 +44,21 @@ func WithErrorServerDeleteCreatingServer(perrResp IErrorRespone) func(sdkError I
}
}

func WithErrorServerExpired(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
if perrResp == nil {
return
}

errMsg := perrResp.GetMessage()
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternServerExpired) {
sdkError.WithErrorCode(EcVServerServerExpired).
WithMessage(errMsg).
WithErrors(perrResp.GetError())
}
}
}

func WithErrorServerExceedQuota(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
if perrResp == nil {
Expand Down
1 change: 1 addition & 0 deletions vngcloud/services/compute/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (s *ComputeServiceV2) UpdateServerSecgroupsByServerId(popts IUpdateServerSe
if _, sdkErr := s.VServerClient.Put(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorServerNotFound(errResp),
lserr.WithErrorServerExpired(errResp),
lserr.WithErrorSecgroupNotFound(errResp)).
WithKVparameters("projectId", s.getProjectId(),
"serverId", popts.GetServerId(),
Expand Down

0 comments on commit cbdb64d

Please sign in to comment.