code: @ExceptionHandler(ValidationException.class)
      public ResponseEntity<ExceptionInfo> handleValidationException(final HttpServletRequest request,
              final ValidationException ex) {
          logRequest(request, ex);
  
          final ExceptionInfo response = new ExceptionInfo();
          response.setMessage(ex.getMessage());
          response.setExceptionClass(ex.getClass().getName());
          response.setErrorCode(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey());
  
          return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
      }
docs: Method for handling exception of type ValidationException which is thrown
  in case the request is rejected due to invalid requests. Called by the
  Spring-Framework for exception handling.
  
  @param request
  the Http request
  @param ex
  the exception which occurred
  @return the entity to be responded containing the exception information
  as entity.