Last active
January 31, 2018 06:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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