-
Notifications
You must be signed in to change notification settings - Fork 38.5k
ProblemDetails not showing cause of validation error #34061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this behavior is implemented by Spring Framework in I'll transfer this issue there for further discussion. |
I think that should work out of the box, because the defaults for |
I don't think Spring Framework ships with message sources by default. The reference doc mentions the Message Code Arguments that are available, not the default messages. Can you try and get back to us? Thanks! |
Here are my results, I tried all 3 variants:
Result: the validation message is displayed, but the targeting parameter is missing completely:
I also tried
Result: title is taken plain, without replacing the {0} value:
Result: Exception on message rendering:
So, while the first message result improves the error message, I still think there is much room for improvement (at least including the parameter name that caused the error). |
@membersound You should try to use placeholder
|
We do not want to leak information, and also cannot easily format validation errors transparently because we have no knowledge of what's in the validation message, e.g. it could already have the parameter name, and likewise internationalization also requires customization. There are just too many variables to be able to provide something better out of the box, while keeping it customizable. You have a few options. Adding a To customize the validation messages, you can set it on the annotation: You can also use your message.properties to customize validation messages as explained here. For example the following will customize all Size related errors across the application: Size={0} must be > {2} and < {1} There is also an option to handle HandlerMethodValidationException with a visitor that lets you handle validation errors by type of method parameter (request param, header, cookie, etc). |
You can customize those, but there are no arguments, so leave out the |
spring-boot-3.4.0
When I enable problem-details, the validation message of my parameters should be shown in the response.
But it is still hidden. Example:
Result:
Expected result: something like "token [size = 3] ... too short"... as hint for the client-user how he can fix his 400.
The text was updated successfully, but these errors were encountered: