public ResponseEntity handleConstraintViolationException()

in ddm-rrm-rest-api/src/main/java/com/epam/digital/data/platform/management/restapi/exception/ApplicationExceptionHandler.java [298:326]


  public ResponseEntity<DetailedErrorResponse> handleConstraintViolationException(
      ConstraintViolationException exception) {
    var annotation = getAnnotationFromConstraintViolationException(exception);
    if (annotation instanceof BusinessProcess) {
      log.warn("Business process content has errors");
      return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
          .body(newDetailedResponse(BUSINESS_PROCESS_CONTENT_EXCEPTION, exception));
    }
    if (annotation instanceof VersionCandidate) {
      log.warn("Version candidate name or description is invalid");
      return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
          .body(newDetailedResponse(INVALID_VERSION_CANDIDATE_EXCEPTION, exception));
    }
    if (annotation instanceof ExistingVersionCandidate) {
      return ResponseEntity.status(HttpStatus.NOT_FOUND)
          .body(newDetailedResponse(CHANGE_NOT_FOUND, exception));
    }
    if (annotation instanceof TableName) {
      return ResponseEntity.status(HttpStatus.BAD_REQUEST)
          .body(newDetailedResponse(HttpStatus.BAD_REQUEST.getReasonPhrase(), exception));
    }
    if (annotation instanceof DDMExtensionChangelogFile) {
      return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
          .body(newDetailedResponse(INVALID_CHANGELOG, exception));
    }
    log.error("Constraint violation exception");
    return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
        .body(newDetailedResponse(CONSTRAINT_VIOLATION_EXCEPTION, exception));
  }