Skip to content
Permalink
Browse files

Merge pull request #1373 from ingarabr/feature/http-client-debug-info

add context to json paring errors
  • Loading branch information
fthomas committed Mar 25, 2020
2 parents b4df9c0 + 40fd2fa commit 77925ac9fe5fdb46a32273cb83054875f4e31e03
Showing with 13 additions and 2 deletions.
  1. +13 −2 modules/core/src/main/scala/org/scalasteward/core/util/HttpJsonClient.scala
@@ -22,7 +22,7 @@ import io.circe.{Decoder, Encoder}
import org.http4s.Method.{GET, POST}
import org.http4s.circe.{jsonEncoderOf, jsonOf}
import org.http4s.client.Client
import org.http4s.{Headers, Method, Request, Response, Status, Uri}
import org.http4s.{DecodeFailure, Headers, HttpVersion, Method, Request, Response, Status, Uri}

import scala.util.control.NoStackTrace

@@ -43,7 +43,7 @@ final class HttpJsonClient[F[_]: Sync](
private def request[A: Decoder](method: Method, uri: Uri, modify: ModReq): F[A] =
client.expectOr[A](modify(Request[F](method, uri)))(resp =>
toUnexpectedResponse(uri, method, resp)
)(jsonOf[F, A])
)(jsonOf[F, A].transform(_.leftMap(failure => JsonParseError(uri, method, failure))))

private def toUnexpectedResponse(
uri: Uri,
@@ -55,6 +55,17 @@ final class HttpJsonClient[F[_]: Sync](
}
}

final case class JsonParseError(
uri: Uri,
method: Method,
underlying: DecodeFailure
) extends DecodeFailure {
val message = s"uri: $uri\nmethod: $method\nmessage: ${underlying.message}"
override def cause: Option[Throwable] = underlying.some
override def toHttpResponse[F[_]](httpVersion: HttpVersion): Response[F] =
underlying.toHttpResponse(httpVersion)
}

final case class UnexpectedResponse(
uri: Uri,
method: Method,

0 comments on commit 77925ac

Please sign in to comment.
You can’t perform that action at this time.