Skip to content

Commit

Permalink
refactor: improve validation handling (DEV-228) (#1937)
Browse files Browse the repository at this point in the history
  • Loading branch information
subotic committed Nov 12, 2021
1 parent 04d57f1 commit 94d7d3f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions webapi/src/main/scala/org/knora/webapi/routing/KnoraRoute.scala
Expand Up @@ -153,9 +153,17 @@ abstract class KnoraRoute(routeData: KnoraRouteData) extends KnoraRouteFactory(r
def toFuture[A](either: Either[Throwable, A]): Future[A] = either.fold(Future.failed, Future.successful)

/**
* Helper method converting an [[zio.prelude.Validation]] to a [[Future]].
* FIXME: only the first error is returned, which defeats the purpose, but don't know better at the moment.
* Helper method converting an [[zio.prelude.Validation]] to a [[scala.concurrent.Future]].
*/
def toFuture[A](validation: Validation[Throwable, A]): Future[A] =
validation.fold(errors => Future.failed(errors.head), Future.successful)
validation.fold(
errors => {
val newThrowable: Throwable = errors.tail.foldLeft(errors.head) { (acc, err) =>
acc.addSuppressed(err)
acc
}
Future.failed(newThrowable)
},
Future.successful
)
}

0 comments on commit 94d7d3f

Please sign in to comment.