Slide 37
Slide 37 text
object ApplicationErrorConverters {
implicit class RepositoryError2ApplicationError[E](val e: Either[RepositoryError, E])
extends AnyVal {
def toApplicationError: Either[ApplicationError, E] =
e.fold(
{
case _: RepositoryOptimisticError => Left(ConflictError)
case _: RepositoryNotFoundError => Left(NoContentsError)
case _: RepositoryAlreadyExistsError =>
Left(BadRequestError(Some("already_exists")))
case RepositorySystemError(t) => Left(InternalServerError(t))
},
Right(_)
)
}
}