-
Notifications
You must be signed in to change notification settings - Fork 41.1k
@PathVariable validation gives 500 instead of 400 #10471
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 forgot, here is an example project: |
@destan Is it on Spring Boot 1.5.x or 2.x? |
@php-coder it's
also I've added an example project as zip in previous comment. |
@php-coder is there anything I can do to help? |
@destan Let's wait a response from Spring Boot developers. |
Here are commands to run on the sample
|
With the POST call (the one that returns 400) the following exception is thrown from the
Since With the GET call the following exception is thrown:
This one appears to be thrown by the validation proxy. Spring is effectively calling the method with a short parameter and the This logic is all part of Spring MVC so I think the issue should be raised on their JIRA. It's quite possible that they won't consider it a bug, or might not be able to fix it because of breaking back compatibility. If you want consistent status messages, I think your best bet for now is to implement your own |
I'll close this one here since there's not much we can do in Spring Boot. @destan If you raise a framework issue would you be so kind as to paste link here. |
Solution which worked for me in SpringBoot 2.1.1.RELEASE was to add an additional ExceptionHandler to the ControllerAdvice class as follows:
|
@Laharnaman Annotate the class with |
@philwebb How does Spring Boot handle validation/bind issues normally? I see https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java#L407 passes |
Actually, it looks like re-throwing the exception from within an overridden
|
|
it is checked: package org.springframework.validation;
public class BindException extends Exception implements BindingResult { |
In my case, I needed to add an |
When validating
@PathVariable
s as shown above it gives 500 instead of 400. I think this is both wrong and unintuitive because this is a similar case when we validate@RequestBody
s which give 400 when validation fails.response of
fails
method when validation fails:response of
works
method when validation fails:is there any plan to fix this or is this state considered normal?
The text was updated successfully, but these errors were encountered: