From cbdb64de7239722e807f5d94e1bba06f3765bbb2 Mon Sep 17 00:00:00 2001 From: "Cuong. Duong Manh" Date: Fri, 7 Jun 2024 10:15:28 +0700 Subject: [PATCH] [feat] update error handler for api update secgroup for server --- vngcloud/sdk_error/error_codes.go | 1 + vngcloud/sdk_error/server.go | 16 ++++++++++++++++ vngcloud/services/compute/v2/server.go | 1 + 3 files changed, 18 insertions(+) diff --git a/vngcloud/sdk_error/error_codes.go b/vngcloud/sdk_error/error_codes.go index f5451ca..e2f6d20 100644 --- a/vngcloud/sdk_error/error_codes.go +++ b/vngcloud/sdk_error/error_codes.go @@ -81,6 +81,7 @@ const ( const ( EcVServerServerNotFound = ErrorCode("VngCloudVServerServerNotFound") EcVServerServerDeleteCreatingServer = ErrorCode("VngCloudVServerServerDeleteCreatingServer") + EcVServerServerExpired = ErrorCode("VngCloudVServerServerExpired") EcVServerServerExceedQuota = ErrorCode("VngCloudVServerServerExceedQuota") EcVServerServerDeleteDeletingServer = ErrorCode("VngCloudVServerServerDeleteDeletingServer") EcVServerServerDeleteBillingServer = ErrorCode("VngCloudVServerServerDeleteBillingServer") diff --git a/vngcloud/sdk_error/server.go b/vngcloud/sdk_error/server.go index d9ba103..d27f3a9 100644 --- a/vngcloud/sdk_error/server.go +++ b/vngcloud/sdk_error/server.go @@ -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) { @@ -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 { diff --git a/vngcloud/services/compute/v2/server.go b/vngcloud/services/compute/v2/server.go index 5eed692..3f3e134 100644 --- a/vngcloud/services/compute/v2/server.go +++ b/vngcloud/services/compute/v2/server.go @@ -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(),