apicollective / apibuilder-generator

MIT License
54 stars 36 forks source link

HTTP4S Generator: Add headers to FailedRequest model #627

Open barryoneill opened 3 years ago

barryoneill commented 3 years ago

In the http4s client, when a codec fails to parse the expected JSON, it creates a FailedRequest model:

  def parseJson[F[_]: Sync, T](
      className: String,
      r: org.http4s.Response[F]
    )(implicit decoder: io.circe.Decoder[T]): F[T] = r.attemptAs[T].value.flatMap {
      case Right(value) => Sync[F].pure(value)
      case Left(error) => Sync[F].raiseError(new com.foo.bar.api.v2.errors.FailedRequest( r.status.code, s"Invalid json for class[" + className + "]", None, error))
    }

It would be desirable to have the headers from the response to be included in this FailedRequest.

gheine commented 3 years ago

@barryoneill we'd be happy to consider your PR ;-)

barryoneill commented 3 years ago

Just a moment while I convert it all to tagless final :)

gheine commented 3 years ago

/unsubscribe