Skip to content
Permalink
Browse files
refactor: improve validation handling (DEV-228) (#1937)
  • Loading branch information
subotic committed Nov 12, 2021
1 parent 04d57f1 commit 94d7d3fe882134c0a9b31124050a71ab7fe2deb6
Showing with 11 additions and 3 deletions.
  1. +11 −3 webapi/src/main/scala/org/knora/webapi/routing/KnoraRoute.scala
@@ -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.