Skip to content

fix: improve error messaging when saving custom field#7578

Merged
kyle-ssg merged 4 commits into
mainfrom
fix/metadata-field-error-messaging
May 22, 2026
Merged

fix: improve error messaging when saving custom field#7578
kyle-ssg merged 4 commits into
mainfrom
fix/metadata-field-error-messaging

Conversation

@kyle-ssg
Copy link
Copy Markdown
Member

@kyle-ssg kyle-ssg commented May 22, 2026

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to `docs/` if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to #7424

This PR improves the error messaging for creating metadata fields.

How did you test this code?

  • As a project-admin-only user, attempted to create a metadata field and confirmed the toast now surfaces the backend permission detail and explains that the field was created but not bound to any entity.
  • As an org admin, created a custom field successfully — no regression.

Replace the generic "Failed to save custom field" toast with a phase-aware
message that distinguishes a failure to create the MetadataField from a
failure to bind it to a content type. When the field was created but the
binding call failed (e.g. 403 for non-admin project administrators, see
#7424), tell the user the field is orphaned and needs an organisation
administrator to finish or remove it. Other errors now bubble up the
backend detail string instead of being swallowed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kyle-ssg kyle-ssg requested a review from a team as a code owner May 22, 2026 11:55
@kyle-ssg kyle-ssg requested review from talissoncosta and removed request for a team May 22, 2026 11:55
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview, Comment May 22, 2026 12:07pm
flagsmith-frontend-staging Ready Ready Preview, Comment May 22, 2026 12:07pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview May 22, 2026 12:07pm

Request Review

@github-actions github-actions Bot added front-end Issue related to the React Front End Dashboard fix labels May 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-7578 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-7578 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-7578 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-7578 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-7578 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7578 Finished ✅ Results

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances error handling in the CreateMetadataField component by introducing logic to extract specific error details from API responses and providing context-aware messages for different failure phases, such as field creation versus binding. A review comment identifies that the current error extraction logic is too restrictive and suggests a more robust implementation to handle various backend error formats, such as those from Django Rest Framework, to ensure users receive informative feedback.

Comment thread frontend/web/components/modals/CreateMetadataField.tsx Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Visual Regression

No baseline found — first run. Baselines will be generated after merge to main.
View full report

@kyle-ssg kyle-ssg changed the title fix(metadata): improve error messaging when saving custom field fix: improve error messaging when saving custom field May 22, 2026
Address review feedback on #7578: getErrorDetail now extracts messages
from DRF field-error objects, non_field_errors arrays, raw string errors,
and network failures with message/error properties.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the custom getErrorDetail/buildErrorMessage parsers in favour of the
existing <ErrorMessage> component, which already handles DRF detail,
non_field_errors, field-error objects and Error instances.

Store the caught error in state and render it inline, with a separate
warning banner when a successful create was followed by a binding
failure (the orphaned-field case from #7424).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When a custom field create succeeds but the binding call fails, show
only the orphan-explanation message rather than stacking it above the
generic permission error. The orphan message already covers the user's
next step.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@talissoncosta talissoncosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for handling that @kyle-ssg !

@kyle-ssg kyle-ssg merged commit e5ba08a into main May 22, 2026
36 of 44 checks passed
@kyle-ssg kyle-ssg deleted the fix/metadata-field-error-messaging branch May 22, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants