Skip to content

fix(rest): return 400 for missing required request parameters instead of 500#3777

Open
Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Shivamrut:3776
Open

fix(rest): return 400 for missing required request parameters instead of 500#3777
Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Shivamrut:3776

Conversation

@Shivamrut
Copy link
Contributor

@Shivamrut Shivamrut commented Feb 28, 2026

Fixes #3776

Summary

  • MissingServletRequestParameterException extends ServletRequestBindingExceptionBindExceptionException (not RuntimeException), causing it to bypass the RuntimeException → 400 handler and fall into the catch-all Exception → 500 handler in RestExceptionHandler
  • Similarly, MissingServletRequestPartException (thrown for missing multipart file parameters) follows the same inheritance chain and was also incorrectly returning 500
  • Added a dedicated handler for both MissingServletRequestParameterException and MissingServletRequestPartException that correctly returns 400 Bad Request
  • Imports added accordingly

Screenshot

Before:
image
After:
image

Test plan

  • Send GET /api/attachments with no sha1 query parameter
  • Verify response is now 400 Bad Request with message Required request parameter 'sha1' for method parameter type String is not present
  • Verify GET /api/attachments?sha1=<valid_hash> still works correctly and returns 200
  • Verify other existing exception handler behaviours are unaffected

Related Direct Fixes

Query Parameter Endpoints (MissingServletRequestParameterException)

Endpoint Missing Parameter
GET /api/attachments sha1
POST /api/moderationrequest/validate entityType or entityId
POST /api/departments/writePathFolder pathFolder
GET /api/reports module
GET /api/reports/download module or token
PATCH /api/releases/mergereleases mergeTargetId or mergeSourceId
PATCH /api/vendors/mergeVendors mergeTargetId or mergeSourceId
GET /api/schedule/status serviceName

Multipart File Endpoints (MissingServletRequestPartException)

Endpoint Missing Parameter
POST /api/attachments files
POST /api/importExport/uploadComponent file
POST /api/importExport/uploadRelease file
POST /api/importExport/componentAttachment file

All these endpoints previously returned 500 Internal Server Error instead of 400 Bad Request for missing parameters.

@Shivamrut Shivamrut force-pushed the 3776 branch 2 times, most recently from 13c50e7 to e81389c Compare February 28, 2026 14:38
@GMishx GMishx added needs code review needs general test This is general testing, meaning that there is no org specific issue to check for labels Mar 2, 2026
@GMishx
Copy link
Member

GMishx commented Mar 2, 2026

@Shivamrut please squash all 6 commits into one. This PR works on a single fix and thus, there should be only 1 commit.

… of 500

MissingServletRequestParameterException extends ServletRequestBindingException
which extends Exception (not RuntimeException), causing it to bypass the
RuntimeException->400 handler and fall into the catch-all Exception->500 handler.

Similarly, MissingServletRequestPartException (thrown for missing multipart file
parameters) follows the same inheritance chain and was also incorrectly returning 500.

Added dedicated handlers for both exceptions that correctly return 400 Bad Request.

Fixes eclipse-sw360#3776

Signed-off-by: Shivamrut <gshivamrut@gmail.com>
@Shivamrut
Copy link
Contributor Author

@GMishx Thanks for review. I have squashed all commits. Anymore changes required please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs code review needs general test This is general testing, meaning that there is no org specific issue to check for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET /api/attachments returns 500 Internal Server Error instead of 400 Bad Request when sha1 parameter is missing

2 participants