fix(rest): return 400 for missing required request parameters instead of 500#3777
Open
Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Open
fix(rest): return 400 for missing required request parameters instead of 500#3777Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Shivamrut wants to merge 2 commits intoeclipse-sw360:mainfrom
Conversation
13c50e7 to
e81389c
Compare
Member
|
@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>
Contributor
Author
|
@GMishx Thanks for review. I have squashed all commits. Anymore changes required please let me know. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3776
Summary
MissingServletRequestParameterExceptionextendsServletRequestBindingException→BindException→Exception(notRuntimeException), causing it to bypass theRuntimeException → 400handler and fall into the catch-allException → 500handler inRestExceptionHandlerMissingServletRequestPartException(thrown for missing multipart file parameters) follows the same inheritance chain and was also incorrectly returning500MissingServletRequestParameterExceptionandMissingServletRequestPartExceptionthat correctly returns400 Bad RequestScreenshot
Before:


After:
Test plan
GET /api/attachmentswith nosha1query parameter400 Bad Requestwith messageRequired request parameter 'sha1' for method parameter type String is not presentGET /api/attachments?sha1=<valid_hash>still works correctly and returns200Related Direct Fixes
Query Parameter Endpoints (
MissingServletRequestParameterException)GET /api/attachmentssha1POST /api/moderationrequest/validateentityTypeorentityIdPOST /api/departments/writePathFolderpathFolderGET /api/reportsmoduleGET /api/reports/downloadmoduleortokenPATCH /api/releases/mergereleasesmergeTargetIdormergeSourceIdPATCH /api/vendors/mergeVendorsmergeTargetIdormergeSourceIdGET /api/schedule/statusserviceNameMultipart File Endpoints (
MissingServletRequestPartException)POST /api/attachmentsfilesPOST /api/importExport/uploadComponentfilePOST /api/importExport/uploadReleasefilePOST /api/importExport/componentAttachmentfileAll these endpoints previously returned
500 Internal Server Errorinstead of400 Bad Requestfor missing parameters.