Skip to content

fix: return readable errors for unrecognised JSON fields#580

Merged
dricazenck merged 6 commits intoWomen-Coding-Community:mainfrom
dricazenck:fix/readable-json-errors
Mar 29, 2026
Merged

fix: return readable errors for unrecognised JSON fields#580
dricazenck merged 6 commits intoWomen-Coding-Community:mainfrom
dricazenck:fix/readable-json-errors

Conversation

@dricazenck
Copy link
Copy Markdown
Collaborator

Description

When the API received a request body containing unknown JSON fields, it previously returned an opaque or unhelpful error response that gave
clients no actionable information. This fix adds proper handling in GlobalExceptionHandler for deserialization failures so that clients
receive a clear error message identifying the unrecognised field. This improves the developer experience when integrating with the API and
reduces debugging friction. The mentorship page feedback content is also refreshed with 2025 cycle testimonials and link field ordering is
aligned with the CMS schema convention.

Related PR

Women-Coding-Community/wcc-frontend#259

Change Type

  • Bug Fix
  • Test
  • Other

Pull request checklist

Please check if your PR fulfills the following requirements:

Unknown fields in request payloads currently surface as generic parse
failures, which makes API validation errors harder to understand and
debug. Handle unreadable JSON with a clearer message that points to the
exact field path and lists the allowed properties so invalid requests
can be corrected quickly.
The new JSON error handler was only covered for unknown fields, which
left the generic HttpMessageNotReadableException fallback behavior
untested. Add a regression test for an invalid enum value so future
changes do not accidentally alter the fallback error contract.
The feedback section is refreshed with testimonials from the 2025
mentorship cycle, replacing the 2024 entries to keep the displayed
content current and relevant for prospective mentors and mentees.
The `link` field is also reordered before `items` in the mentor and
mentee sections to match a consistent field ordering convention used
across the CMS content schema.
Copy link
Copy Markdown
Contributor

@womencodingcommunity womencodingcommunity left a comment

Choose a reason for hiding this comment

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

Great work on this PR! The GlobalExceptionHandler improvement is well-structured — the pattern-matched instanceof, sorted allowed-fields list, and the integration test going through the full MockMvc stack all give good confidence in the behaviour. The mentorship page refresh and JSON field reordering are clean too.

Warnings to address before or shortly after merge:

  • import com.wcc.platform.domain.exceptions.*; — replace with the explicit imports that are actually needed; this will likely fail the PMD AvoidStarImport check.
  • formatPath parameter uses java.util.List inline — add an import java.util.List; and use the short name.

Info / optional follow-ups (no blocker):

  • The error path currently ends with the field name itself (skills.areas[0].name), making it slightly redundant with the field name in the message prefix — see the inline suggestion for how to trim to the parent location.
  • assertThrows is used to capture a setup exception rather than as an assertion — a try-catch reads more clearly in that role.

@sonarqubecloud
Copy link
Copy Markdown

@dricazenck dricazenck merged commit 58db722 into Women-Coding-Community:main Mar 29, 2026
3 of 4 checks passed
@dricazenck dricazenck deleted the fix/readable-json-errors branch March 29, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants