Surface real error when saving a security attribute fails
What does this MR do?
When creating a security attribute fails — for example, when adding one would exceed the per-category attribute limit — the UI showed a generic banner ("An error has occurred while saving the security attribute.") even though the GraphQL response contained the specific, actionable message ("Category cannot have more than N attributes.").
The backend is correct: the limit is enforced in Mutations::Security::Attributes::Create#validate_category_attribute_limit, which raises a top-level GraphQL error. The bug was purely frontend — saveAttribute() in configure_attributes.vue hard-coded the generic message and ignored error.message, unlike the sibling saveCategory() which handles it correctly.
Changes
configure_attributes.vue:- Catch block now falls back to
error?.messagebefore the generic string, so the real error is shown. - Both create and update
.thenblocks now check the mutation payloaderrorsarray and throw the first error (mirroringsaveCategory), covering service-level validation errors returned in the payload.
- Catch block now falls back to
- Tests: converted the attribute-failure test into an
it.eachcovering the payload-errorspath, a top-level rejection carrying a message, and the generic fallback. Also fixed the test to let the group query resolve before saving (previously it threw onselectedCategory.idand never exercised the mutation).
Testing
jest ee/spec/frontend/security_configuration/components/security_attributes/configure_attributes_spec.js — 19 examples, 0 failures. ESLint and Prettier clean.
Screenshots or screen recordings
How to setup and validate locally
- In the rails console, create a category and add the limit of 100 attributes to it
namespace = Namespace.find 33 # flightjs on my GDK
categories = 1
attributes = 100
categories.times do |c|
category = Security::Category.create!(
name: "cat-#{c + 10}",
editable_state: :editable,
namespace: namespace
)
#color per category
color = SecureRandom.hex(3)
attributes.times do |a|
Security::Attribute.create!(
name: "#{a + 1}-attr, cat-#{c + 1} ",
description: "Generated attribute #{a + 1}",
color: "##{color}",
editable_state: :editable,
security_category: category,
namespace: namespace
)
end
end
- Navigate to FlightJS group -> Security configuration menu item -> Security Attributes tab
- Attempt to create the 101st attribute
- Observe the improved error message
References
No related issue. I discovered the bug while working on something else and opened an MR for it.
| Before | After | |
|---|---|---|
| Attempting to add an attribute goes over the limit |