Skip to content

fix(api): improve validation error responses in InvolvedCancerStudyEx..#11937

Open
tim48-robot wants to merge 5 commits intocBioPortal:masterfrom
tim48-robot:fix/api-validation-improvements
Open

fix(api): improve validation error responses in InvolvedCancerStudyEx..#11937
tim48-robot wants to merge 5 commits intocBioPortal:masterfrom
tim48-robot:fix/api-validation-improvements

Conversation

@tim48-robot
Copy link

@tim48-robot tim48-robot commented Feb 4, 2026

Summary

This PR improves the API validation error handling in InvolvedCancerStudyExtractorInterceptor. Previously, malformed JSON or empty request bodies would result in a silent failure (HTTP 200 OK with no data) or sometimes an internal server error. This change ensures that a proper HTTP 400 Bad Request is returned with a descriptive JSON error message.

Changes

  • Updated InvolvedCancerStudyExtractorInterceptor to catch JSON parsing exceptions and return HTTP 400.
  • Added sendBadRequestResponse helper to standardize error responses.
  • Implemented message truncation to remove technical Jackson source details (e.g., "at [Source: ...]") for cleaner client feedback.
  • Applied the fix consistently across 20+ filter extraction methods.

Verification

Verified locally via curl:

  • Malformed JSON correctly returns 400 Bad Request.
  • Empty request body returns 400 Bad Request.
  • Valid requests are still processed correctly.

Checks

Videos

2026-02-04.10-45-38.mp4

…tractorInterceptor

- Return HTTP 400 Bad Request instead of silent failures on malformed JSON
- Truncate technical Jackson details from error messages for cleaner feedback
- Ensure consistency across all filter extraction methods
@tim48-robot
Copy link
Author

on the video i havent tried the new localize docker after trruncating technical jackson details.

@tim48-robot tim48-robot marked this pull request as ready for review February 4, 2026 08:33
@tim48-robot
Copy link
Author

@inodb would love if you could do a review!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves error handling in the InvolvedCancerStudyExtractorInterceptor to return proper HTTP 400 Bad Request responses for malformed JSON or invalid request bodies, instead of silently failing with HTTP 200 OK or causing internal server errors.

Changes:

  • Added sendBadRequestResponse helper method to standardize HTTP 400 error responses with JSON error messages
  • Updated 25 filter extraction methods to accept HttpServletResponse parameter and call sendBadRequestResponse on parsing errors
  • Implemented message truncation to remove technical Jackson source location details for cleaner error messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tim48-robot
Copy link
Author

thanks for the review copilot, will check on it & resolve

- Use ObjectMapper for proper JSON escaping (prevents injection)
- Reuse ErrorResponse class for consistency with GlobalExceptionHandler
- Check response.isCommitted() before writing error response
- Catch IOException specifically instead of broad Exception
- Fix log message typo (clinicalDataBinCountFilter -> clinicalDataCountFilter)
- Add comprehensive unit tests for error handling scenarios
@tim48-robot tim48-robot force-pushed the fix/api-validation-improvements branch from 175de37 to aa0ba5c Compare February 5, 2026 03:36
Exception.getMessage() can return null for some exceptions (e.g., NPE without message).
Added null-safe handling in sendBadRequestResponse to prevent NPE when processing error messages.
@tim48-robot tim48-robot force-pushed the fix/api-validation-improvements branch from 63376d9 to b0a78e4 Compare February 5, 2026 04:17
@tim48-robot
Copy link
Author

everything is done! i think its ready now

@tim48-robot
Copy link
Author

hey @haynescd ! could you take a review?

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.

1 participant