Skip to content

Commit

Permalink
[chore] update error handler for api create endpoint:
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Aug 14, 2024
1 parent c80d15e commit 71f15e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion vngcloud/sdk_error/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ func WithErrorContainInvalidCharacter(perrResp IErrorRespone) func(sdkError ISdk
}

if lstr.ToUpper(lstr.TrimSpace(perrResp.GetError().Error())) == "CONTAIN_INVALID_CHARACTER" {
sdkError.WithErrorCode(EcContainInvalidCharacter).
sdkError.WithErrorCode(EcVNetworkContainInvalidCharacter).
WithMessage(perrResp.GetMessage()).
WithErrors(perrResp.GetError())
}
}
}

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

if lstr.ToUpper(lstr.TrimSpace(perrResp.GetError().Error())) == "LOCK_ON_PROCESS" {
sdkError.WithErrorCode(EcVNetworkLockOnProcess).
WithMessage(perrResp.GetMessage()).
WithErrors(perrResp.GetError())
}
Expand Down
3 changes: 2 additions & 1 deletion vngcloud/sdk_error/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ const (
EcVNetworkEndpointOfVpcExists = ErrorCode("EndpointOfVpcIsExists")
EcVNetworkEndpointNotFound = ErrorCode("VngCloudVNetworkEndpointNotFound")
EcVNetworkEndpointPackageNotBelongToEndpointService = ErrorCode("EndpointPackageNotBelongToEndpointService")
EcContainInvalidCharacter = ErrorCode("ContainInvalidCharacter")
EcVNetworkContainInvalidCharacter = ErrorCode("ContainInvalidCharacter")
EcVNetworkLockOnProcess = ErrorCode("LockOnProcess")
)
1 change: 1 addition & 0 deletions vngcloud/services/network/v1/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (s *NetworkServiceV1) CreateEndpoint(popts ICreateEndpointRequest) (*lsenti
if _, sdkErr := s.VNetworkClient.Post(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorEndpointOfVpcExists(errResp),
lserr.WithErrorLockOnProcess(errResp),
lserr.WithErrorEndpointPackageNotBelongToEndpointService(errResp),
lserr.WithErrorContainInvalidCharacter(errResp)).
WithKVparameters("projectId", s.getProjectId())
Expand Down

0 comments on commit 71f15e9

Please sign in to comment.