public ResponseEntity handleConstraintViolationException()

in digital-document-service/src/main/java/com/epam/digital/data/platform/dgtldcmnt/exception/RestExceptionHandler.java [106:121]


  public ResponseEntity<SystemErrorDto> handleConstraintViolationException(
      ConstraintViolationException exception) {
    var error = SystemErrorDto.builder()
        .traceId(MDC.get(BaseRestExceptionHandler.TRACE_ID_KEY))
        .message(exception.getMessage())
        .build();
    var annotation = getAnnotationFromConstraintViolationException(exception);
    if (annotation instanceof AllowedUploadedDocument) {
      log.warn(exception.getMessage());
      error.setCode(HttpStatus.UNPROCESSABLE_ENTITY.getReasonPhrase());
      return new ResponseEntity<>(error, HttpStatus.UNPROCESSABLE_ENTITY);
    }
    log.error("Constraint violation exception");
    error.setCode(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
    return new ResponseEntity<>(error, HttpStatus.INTERNAL_SERVER_ERROR);
  }