All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.touk.nussknacker.ui.validation.FatalValidationError.scala Maven / Gradle / Ivy

There is a newer version: 1.17.0
Show newest version
package pl.touk.nussknacker.ui.validation

import pl.touk.nussknacker.restmodel.validation.ValidationResults.{NodeValidationError, ValidationResult}
import pl.touk.nussknacker.ui.{BadRequestError, NuDesignerError}
import pl.touk.nussknacker.ui.validation.FatalValidationError.formatError

object FatalValidationError {

  def renderNotAllowedAsError(validationResult: ValidationResult): Either[NuDesignerError, ValidationResult] = {
    if (validationResult.renderNotAllowedErrors.isEmpty) {
      Right(validationResult)
    } else {
      Left[NuDesignerError, ValidationResult](FatalValidationError(validationResult.renderNotAllowedErrors))
    }
  }

  def saveNotAllowedAsError(validationResult: ValidationResult): ValidationResult = {
    if (validationResult.saveNotAllowedErrors.isEmpty) {
      validationResult
    } else {
      throw FatalValidationError(validationResult.saveNotAllowedErrors)
    }
  }

  private def formatError(e: NodeValidationError) = s"${e.message}:${e.description}"

}

final case class FatalValidationError(errors: List[NodeValidationError])
    extends BadRequestError(errors.map(formatError).mkString(",")) {}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy