In our application we override handleBindException from ResponseEntityExceptionHandler to improve the output of error message.
@Override
protected ResponseEntity<Object> handleBindException(
BindException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
final List<String> errors = new ArrayList<String>();
for (final FieldError error : ex.getBindingResult().getFieldErrors()) {
errors.add(error.getField() + " has an invalid value: " + error.getRejectedValue());
}
for (final ObjectError error : ex.getBindingResult().getGlobalErrors()) {
errors.add(error.getObjectName() + ": " + error.getDefaultMessage());
}
apiError.setStatus(HttpStatus.BAD_REQUEST);
apiError.setMessage(errors.toString());
apiError.generateDate();
return handleExceptionInternal(ex, apiError, headers, apiError.getStatus(), request);
}
Since Spring 6.0 the method is marked as deprecated, removal is planned for 6.1.
I tried to override handleMethodArgumentNotValid Method, but that has no impact.
For example if several arguments are not valid, then a BindException is thrown instead
How can I deal with this problem, so that my solution works with the next upgrade?
In our application we override handleBindException from ResponseEntityExceptionHandler to improve the output of error message.
Since Spring 6.0 the method is marked as deprecated, removal is planned for 6.1.
I tried to override handleMethodArgumentNotValid Method, but that has no impact.
For example if several arguments are not valid, then a BindException is thrown instead
How can I deal with this problem, so that my solution works with the next upgrade?