Skip to content

Instantly share code, notes, and snippets.

@etaque
Last active January 31, 2018 06:30
Show Gist options
  • Save etaque/af2f8f4d93d0750c03c5eea862561604 to your computer and use it in GitHub Desktop.
Save etaque/af2f8f4d93d0750c03c5eea862561604 to your computer and use it in GitHub Desktop.
404 recovering for http4s v0.17 client. Thanks helpful folks from https://gitter.im/http4s/http4s
import cats._
import cats.implicits._
import org.http4s._
import org.http4s.client._
object clientImplicits {
implicit class ClientSyntax[F[_], E](val client: Client[F]) extends AnyVal {
def expectOption[A](
req: F[Request[F]])(implicit dec: EntityDecoder[F, A], E: ApplicativeError[F, E]): F[Option[A]] = {
client.expect[A](req).map[Option[A]](Some(_)).recover {
case UnexpectedStatus(Status.NotFound) => None
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment