in imageCopier/src/main/scala/com/gu/imageCopier/attempt/Attempt.scala [154:176]
def fromEither[A](e: Either[Failure, A]): Attempt[A] =
Attempt(Future.successful(e))
def fromOption[A](optA: Option[A], ifNone: => Failure): Attempt[A] =
fromEither(optA.toRight(ifNone))
/** Run f and catch any non-fatal exceptions from the execution. This is
* typically used to wrap IO SDK calls.
* @param f
* function to run
* @param recovery
* partial function to convert thrown exceptions to Failure types
*/
def catchNonFatal[A](
f: => A
)(recovery: PartialFunction[Throwable, Failure]): Attempt[A] = {
try {
Attempt.Right(f)
} catch {
case NonFatal(t) =>
Attempt.Left(recovery.lift(t).getOrElse(UnknownFailure(t)))
}
}