Skip to content

Commit

Permalink
[enahance] enhance error handler for the api update tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Nov 12, 2024
1 parent 97094a9 commit ec714f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions vngcloud/sdk_error/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,18 @@ func WithErrorEndpointTagNotFound(perrResp IErrorRespone) func(sdkError IError)
WithErrors(perrResp.GetError())
}
}
}

func WithErrorEndpointTagExisted(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}

if lstr.ToUpper(lstr.TrimSpace(perrResp.GetError().Error())) == "TAG_EXISTED" {
sdkError.WithErrorCode(EcVNetworkEndpointTagExisted).
WithMessage(perrResp.GetMessage()).
WithErrors(perrResp.GetError())
}
}
}
1 change: 1 addition & 0 deletions vngcloud/sdk_error/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,5 @@ const (
EcVNetworkContainInvalidCharacter = ErrorCode("ContainInvalidCharacter")
EcVNetworkLockOnProcess = ErrorCode("LockOnProcess")
EcVNetworkEndpointTagNotFound = ErrorCode("EndpointTagNotFound")
EcVNetworkEndpointTagExisted = ErrorCode("EndpointTagExisted")
)
1 change: 1 addition & 0 deletions vngcloud/services/network/v1/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (s *NetworkServiceInternalV1) CreateTagsWithEndpointId(popts ICreateTagsWit

if _, sdkErr := s.VNetworkClient.Post(url, req); sdkErr != nil {
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorEndpointTagExisted(errResp),
lserr.WithErrorEndpointTagNotFound(errResp)).
WithKVparameters("projectId", s.getProjectId()).
WithParameters(popts.GetParameters())
Expand Down

0 comments on commit ec714f8

Please sign in to comment.