Skip to content

Commit

Permalink
[enhance] enhance error handler for api create endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Aug 10, 2024
1 parent 3da2d2f commit c80d15e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestGetEndpointSuccess(t *ltesting.T) {

func TestCreateEndpoint(t *ltesting.T) {
vngcloud := validSdkConfig()
opt := lsnwv1.NewCreateEndpointRequest("cuongdm3-test", "f3d11a4c-f071-4009-88a6-4a21346c8708", "net-5ac170fc-834a-4621-b512-481e09b82fc8", "sub-0c508dd6-5af6-4f0e-a860-35346b530cf1").WithDescription("This is the inter-vpc-loadbalancer for vstorage service")
opt := lsnwv1.NewCreateEndpointRequest("cuongdm3-test", "f3d11a4c-f071-4009-88a6-4a21346c8708", "net-5ac170fc-834a-4621-b512-481e09b82fc8", "sub-0c508dd6-5af6-4f0e-a860-35346b530cf1").WithDescription("This is the service endpoint for vStorage APIs, established by the VKS product. Please refrain from DELETING it manually.")

lb, sdkerr := vngcloud.VNetworkGateway().V1().NetworkService().CreateEndpoint(opt)
if sdkerr != nil {
Expand Down
14 changes: 14 additions & 0 deletions vngcloud/sdk_error/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ func WithErrorEndpointPackageNotBelongToEndpointService(perrResp IErrorRespone)
}
}
}

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

if lstr.ToUpper(lstr.TrimSpace(perrResp.GetError().Error())) == "CONTAIN_INVALID_CHARACTER" {
sdkError.WithErrorCode(EcContainInvalidCharacter).
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 @@ -130,4 +130,5 @@ const (
EcVNetworkEndpointOfVpcExists = ErrorCode("EndpointOfVpcIsExists")
EcVNetworkEndpointNotFound = ErrorCode("VngCloudVNetworkEndpointNotFound")
EcVNetworkEndpointPackageNotBelongToEndpointService = ErrorCode("EndpointPackageNotBelongToEndpointService")
EcContainInvalidCharacter = ErrorCode("ContainInvalidCharacter")
)
3 changes: 2 additions & 1 deletion vngcloud/services/network/v1/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ 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.WithErrorEndpointPackageNotBelongToEndpointService(errResp)).
lserr.WithErrorEndpointPackageNotBelongToEndpointService(errResp),
lserr.WithErrorContainInvalidCharacter(errResp)).
WithKVparameters("projectId", s.getProjectId())
}

Expand Down

0 comments on commit c80d15e

Please sign in to comment.