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

Raise DecodeFailure with MonadError instead of throwing #2506

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions client/src/main/scala/org/http4s/client/oauth1/oauth1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ package object oauth1 {
consumer: Consumer,
callback: Option[Uri],
verifier: Option[String],
token: Option[Token])(implicit F: Monad[F], W: EntityDecoder[F, UrlForm]): F[Request[F]] =
token: Option[Token])(
implicit F: MonadError[F, Throwable],
W: EntityDecoder[F, UrlForm]): F[Request[F]] =
getUserParams(req).map {
case (req, params) =>
val auth = genAuthHeader(req.method, req.uri, params, consumer, callback, verifier, token)
Expand Down Expand Up @@ -106,7 +108,7 @@ package object oauth1 {
UrlCodingUtils.urlEncode(str, spaceIsPlus = false, toSkip = UrlCodingUtils.Unreserved)

private[oauth1] def getUserParams[F[_]](req: Request[F])(
implicit F: Monad[F],
implicit F: MonadError[F, Throwable],
W: EntityDecoder[F, UrlForm]): F[(Request[F], immutable.Seq[(String, String)])] = {
val qparams = req.uri.query.pairs.map { case (k, ov) => (k, ov.getOrElse("")) }

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/org/http4s/Message.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ sealed trait Message[F[_]] { self =>
* If no valid [[Status]] has been described, allow Ok
*
* @param decoder [[EntityDecoder]] used to decode the [[Message]]
* @tparam T type of the result
* @return the effect which will generate the T
* @tparam A type of the result
* @return the effect which will generate the A
*/
def as[T](implicit F: Functor[F], decoder: EntityDecoder[F, T]): F[T] =
attemptAs.fold(throw _, identity)

def as[A](implicit F: MonadError[F, Throwable], decoder: EntityDecoder[F, A]): F[A] =
// n.b. this is foldF in cats master, and will eventually be further optimized with redeem
attemptAs.value.flatMap(_.fold(F.raiseError(_), F.pure(_)))
}

object Message {
Expand Down