Skip to content

Commit

Permalink
[chore] add error category to alert routing
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Oct 24, 2024
1 parent 6a3d055 commit 3ec9945
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
4 changes: 4 additions & 0 deletions vngcloud/sdk_error/categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ const (
const (
ErrCatAll ErrorCategory = "all"
)

const (
ErrCatProductVlb ErrorCategory = "vlb"
)
49 changes: 32 additions & 17 deletions vngcloud/services/loadbalancer/v2/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func (s *LoadBalancerServiceV2) CreateLoadBalancer(popts ICreateLoadBalancerRequ

if _, sdkErr := s.VLBClient.Post(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerExceedQuota(errResp))
lserr.WithErrorLoadBalancerExceedQuota(errResp)).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityLoadBalancer(), nil
Expand All @@ -38,7 +39,8 @@ func (s *LoadBalancerServiceV2) GetLoadBalancerById(popts IGetLoadBalancerByIdRe
if _, sdkErr := s.VLBClient.Get(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound(errResp)).
WithKVparameters("loadBalancerId", popts.GetLoadBalancerId())
WithKVparameters("loadBalancerId", popts.GetLoadBalancerId()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityLoadBalancer(), nil
Expand All @@ -55,7 +57,8 @@ func (s *LoadBalancerServiceV2) ListLoadBalancers(popts IListLoadBalancersReques
WithJsonError(errResp)

if _, sdkErr := s.VLBClient.Get(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp)
return nil, lserr.SdkErrorHandler(sdkErr, errResp).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityListLoadBalancers(), nil
Expand All @@ -78,7 +81,8 @@ func (s *LoadBalancerServiceV2) CreatePool(popts ICreatePoolRequest) (*lsentity.
lserr.WithErrorLoadBalancerNotFound2(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp),
lserr.WithErrorLoadBalancerDuplicatePoolName(errResp)).
WithParameters(popts.ToMap())
WithParameters(popts.ToMap()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityPool(), nil
Expand All @@ -97,7 +101,8 @@ func (s *LoadBalancerServiceV2) UpdatePool(popts IUpdatePoolRequest) lserr.IErro
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound2(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp),
lserr.WithErrorListenerNotFound(errResp))
lserr.WithErrorListenerNotFound(errResp)).
AppendCategories(lserr.ErrCatProductVlb)
}
return nil
}
Expand All @@ -120,7 +125,8 @@ func (s *LoadBalancerServiceV2) CreateListener(popts ICreateListenerRequest) (*l
lserr.WithErrorListenerDuplicateName(errResp),
lserr.WithErrorPoolNotFound(errResp),
lserr.WithErrorListenerDuplicateProtocolOrPort(errResp)).
WithParameters(popts.ToMap())
WithParameters(popts.ToMap()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityListener(), nil
Expand All @@ -139,7 +145,8 @@ func (s *LoadBalancerServiceV2) UpdateListener(popts IUpdateListenerRequest) lse
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound2(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp),
lserr.WithErrorListenerNotFound(errResp))
lserr.WithErrorListenerNotFound(errResp)).
AppendCategories(lserr.ErrCatProductVlb)
}

return nil
Expand All @@ -158,7 +165,8 @@ func (s *LoadBalancerServiceV2) ListListenersByLoadBalancerId(popts IListListene
if _, sdkErr := s.VLBClient.Get(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound(errResp)).
WithKVparameters("loadBalancerId", popts.GetLoadBalancerId())
WithKVparameters("loadBalancerId", popts.GetLoadBalancerId()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityListListeners(), nil
Expand All @@ -177,7 +185,8 @@ func (s *LoadBalancerServiceV2) ListPoolsByLoadBalancerId(popts IListPoolsByLoad
if _, sdkErr := s.VLBClient.Get(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound(errResp)).
WithKVparameters("loadBalancerId", popts.GetLoadBalancerId())
WithKVparameters("loadBalancerId", popts.GetLoadBalancerId()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityListPools(), nil
Expand All @@ -197,7 +206,7 @@ func (s *LoadBalancerServiceV2) UpdatePoolMembers(popts IUpdatePoolMembersReques
lserr.WithErrorLoadBalancerNotFound2(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp),
lserr.WithErrorPoolNotFound(errResp),
lserr.WithErrorMemberMustIdentical(errResp))
lserr.WithErrorMemberMustIdentical(errResp)).AppendCategories(lserr.ErrCatProductVlb)
}

return nil
Expand All @@ -216,7 +225,8 @@ func (s *LoadBalancerServiceV2) ListPoolMembers(popts IListPoolMembersRequest) (
if _, sdkErr := s.VLBClient.Get(url, req); sdkErr != nil {
return nil, lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound(errResp),
lserr.WithErrorPoolNotFound(errResp))
lserr.WithErrorPoolNotFound(errResp)).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityListMembers(), nil
Expand All @@ -234,7 +244,8 @@ func (s *LoadBalancerServiceV2) DeletePoolById(popts IDeletePoolByIdRequest) lse
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorPoolInUse(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp),
lserr.WithErrorPoolNotFound(errResp))
lserr.WithErrorPoolNotFound(errResp)).
AppendCategories(lserr.ErrCatProductVlb)
}

return nil
Expand All @@ -252,7 +263,8 @@ func (s *LoadBalancerServiceV2) DeleteListenerById(popts IDeleteListenerByIdRequ
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound2(errResp),
lserr.WithErrorListenerNotFound(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp))
lserr.WithErrorLoadBalancerNotReady(errResp)).
AppendCategories(lserr.ErrCatProductVlb)
}

return nil
Expand All @@ -270,11 +282,12 @@ func (s *LoadBalancerServiceV2) DeleteLoadBalancerById(popts IDeleteLoadBalancer
return lserr.SdkErrorHandler(sdkErr, errResp,
lserr.WithErrorLoadBalancerNotFound(errResp),
lserr.WithErrorLoadBalancerNotReady(errResp),
lserr.WithErrorLoadBalancerIsCreating(errResp),
lserr.WithErrorLoadBalancerIsCreating(errResp),
lserr.WithErrorLoadBalancerIsDeleting(errResp)).
WithKVparameters(
"loadBalancerId", popts.GetLoadBalancerId(),
"projectId", s.getProjectId())
"projectId", s.getProjectId()).
AppendCategories(lserr.ErrCatProductVlb)
}

return nil
Expand All @@ -296,7 +309,8 @@ func (s *LoadBalancerServiceV2) GetPoolById(popts IGetPoolByIdRequest) (*lsentit
lserr.WithErrorPoolNotFound(errResp)).
WithKVparameters(
"loadBalancerId", popts.GetLoadBalancerId(),
"poolId", popts.GetPoolId())
"poolId", popts.GetPoolId()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityPool(), nil
Expand All @@ -318,7 +332,8 @@ func (s *LoadBalancerServiceV2) GetListenerById(popts IGetListenerByIdRequest) (
lserr.WithErrorListenerNotFound(errResp)).
WithKVparameters(
"loadBalancerId", popts.GetLoadBalancerId(),
"listenerId", popts.GetListenerId())
"listenerId", popts.GetListenerId()).
AppendCategories(lserr.ErrCatProductVlb)
}

return resp.ToEntityListener(), nil
Expand Down

0 comments on commit 3ec9945

Please sign in to comment.