Fix Spring 3.2.2 migration (#1586)

HandlerMethodValidationException is thrown in some validations instead MethodArgumentNotValidException
handle it also

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-02-02 18:32:46 +02:00
committed by GitHub
parent 94ed1f8133
commit 7a7fb7fc3f

View File

@@ -31,6 +31,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.HandlerMethodValidationException;
import org.springframework.web.multipart.MultipartException;
import com.google.common.collect.Iterables;
@@ -164,7 +165,10 @@ public class ResponseExceptionHandler {
* @return the entity to be responded containing the exception information
* as entity.
*/
@ExceptionHandler({ HttpMessageNotReadableException.class, MethodArgumentNotValidException.class, IllegalArgumentException.class })
@ExceptionHandler({
HttpMessageNotReadableException.class,
MethodArgumentNotValidException.class, HandlerMethodValidationException.class,
IllegalArgumentException.class })
public ResponseEntity<ExceptionInfo> handleExceptionCausedByIncorrectRequestBody(final HttpServletRequest request,
final Exception ex) {
logRequest(request, ex);