Browse Source

fix: wrap DetachGroupPolicy error with ErrPolicyNotAttached sentinel

Use credential.ErrPolicyNotAttached so groupErrorToHTTPStatus maps
it to 400 instead of falling back to 500.
pull/8560/head
Chris Lu 1 day ago
parent
commit
cabcd5a697
  1. 2
      weed/admin/dash/group_management.go
  2. 3
      weed/admin/handlers/group_handlers.go

2
weed/admin/dash/group_management.go

@ -207,7 +207,7 @@ func (s *AdminServer) DetachGroupPolicy(ctx context.Context, groupName, policyNa
} }
} }
if !found { if !found {
return fmt.Errorf("policy %s is not attached to group %s", policyName, groupName)
return fmt.Errorf("policy %s is not attached to group %s: %w", policyName, groupName, credential.ErrPolicyNotAttached)
} }
g.PolicyNames = newPolicies g.PolicyNames = newPolicies
if err := s.credentialManager.UpdateGroup(ctx, g); err != nil { if err := s.credentialManager.UpdateGroup(ctx, g); err != nil {

3
weed/admin/handlers/group_handlers.go

@ -24,6 +24,9 @@ func groupErrorToHTTPStatus(err error) int {
if errors.Is(err, credential.ErrUserNotInGroup) { if errors.Is(err, credential.ErrUserNotInGroup) {
return http.StatusBadRequest return http.StatusBadRequest
} }
if errors.Is(err, credential.ErrPolicyNotAttached) {
return http.StatusBadRequest
}
return http.StatusInternalServerError return http.StatusInternalServerError
} }

Loading…
Cancel
Save