The ResponseEntityExceptionHandler
currently handles a MethodArgumentNotValidException
like this:
else if (ex instanceof MethodArgumentNotValidException) {
HttpStatus status = HttpStatus.BAD_REQUEST;
return handleMethodArgumentNotValid((MethodArgumentNotValidException) ex, headers, status, request);
}
This exception is "thrown when validation on an argument annotated with @Valid fails".
I think HttpStatus.UNPROCESSABLE_ENTITY
is a more appropriate status to use because it more clearly shows that the problem is due to the semantics of the request, and not the syntax. Could this default be changed (happy to raise a PR if agreed)?
Comment From: bclozel
Isn't this HTTP status tied to the WebDAV spec only? Wouldn't this feel surprising to get such as specific status outside of the WebDAV use case?
I think this might be the first time we're getting this as a suggestion, and changing this behavior after so many years, without a strong reason, is likely to cause pain in existing applications.
Comment From: rupert-madden-abbott
Sorry yes you are right, this is WebDAV only. 400 is more appropriate. Closing.