feat!(#113): change validation errors to 422 and add custom error messages#135
Merged
Merged
Conversation
…ages
BREAKING CHANGE: Validation error responses now return HTTP 422 instead of 404.
- Change ErrorResponse::invalidParams() and missingParams() from 404 to 422
- Add ParamOption::MESSAGE for custom per-parameter error messages
- Add RequestParameter::getMessage()/setMessage()
- Add 'message' param to #[RequestParam] attribute
- Response format: {message, type, http-code: 422, more-info: {errors: {field: msg}}}
- If no custom message: auto-generates 'Invalid value for parameter X' or 'Required parameter X is missing'
- WebServicesManager now passes RequestParameter objects to ErrorResponse
- Update existing tests for new 422 status code and response format
- 9 new tests covering all message scenarios
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #135 +/- ##
============================================
+ Coverage 93.75% 93.77% +0.01%
- Complexity 1317 1322 +5
============================================
Files 39 39
Lines 3218 3227 +9
============================================
+ Hits 3017 3026 +9
Misses 201 201
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.


Summary
Change validation error HTTP status from 404 to 422 (Unprocessable Entity) and add support for custom per-parameter error messages.
Motivation
404 means "resource not found" — using it for validation errors is semantically incorrect and confuses API consumers. Additionally, the error response only listed parameter names with no human-readable explanation. Fixes #113.
Changes
ErrorResponse::invalidParams()andmissingParams()now return 422ParamOption::MESSAGEoption andRequestParameter::getMessage()/setMessage()#[RequestParam(..., message: 'Custom error')]{"message": "Validation failed", "type": "error", "http-code": 422, "more-info": {"errors": {"field": "message"}}}UI Changes
N/A
How to Test / Verify
9 new tests, 19 assertions. Full suite: 583 tests pass.
Breaking Changes and Migration Steps
Status code changed from 404 to 422 for validation errors. Clients checking for 404 on invalid/missing parameters need to check for 422 instead.
Response format changed:
more-infonow contains{"errors": {"field": "message"}}instead of{"invalid": ["field"]}or{"missing": ["field"]}.Checklist
Related issues
Closes #113