When calling GET endpoint in my scenario you must inform two input parameters code and date, the first one is annotated with @Size(min = 2, max = 2) the second with @DateTimeFormat(iso = DateTimeFormat.ISO.DATE). Said that, if you pass code = 123 and date = 2000-01-AA, you must receive two error messages one regarding ConstraintViolationException and MethodArgumentTypeMismatchException respectively.
Here is my code:
@RestControllerAdvice
public class MyExceptionHandler {
@ExceptionHandler({MethodArgumentTypeMismatchException.class, ConstraintViolationException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse handleArgumentTypeMismatch(RuntimeException ex) {
ErrorResponse errorResponse = ErrorResponse.builder().status(HttpStatus.BAD_REQUEST.value())
.message(INVALID_VALUES_MESSAGE).errorDetail(new ErrorDetail(ex.getMessage())).build();
return errorResponse;
}
}
Currently, I'm only receiving the last parameter error message, in this case date, and the Spring is ignoring the code, is there any way to receive both error messages for code and date?