From 94d7d3fe882134c0a9b31124050a71ab7fe2deb6 Mon Sep 17 00:00:00 2001 From: Ivan Subotic <400790+subotic@users.noreply.github.com> Date: Fri, 12 Nov 2021 08:54:43 +0100 Subject: [PATCH] refactor: improve validation handling (DEV-228) (#1937) --- .../org/knora/webapi/routing/KnoraRoute.scala | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/webapi/src/main/scala/org/knora/webapi/routing/KnoraRoute.scala b/webapi/src/main/scala/org/knora/webapi/routing/KnoraRoute.scala index 22ceb0a136..5b20bb1588 100644 --- a/webapi/src/main/scala/org/knora/webapi/routing/KnoraRoute.scala +++ b/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 + ) }