Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve validation handling (DEV-228) #1937

Merged
merged 1 commit into from Nov 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
)
}