Skip to content

Commit

Permalink
Add HTTP debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonee committed Jun 22, 2024
1 parent 6e9fb57 commit 57d7823
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/scala/http/HttpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import org.http4s.ember.client.EmberClientBuilder
import org.http4s.{Header, Method, Request, Uri}
import org.typelevel.ci.CIString
import com.github.blemale.scaffeine.{AsyncLoadingCache, Scaffeine}
import org.slf4j.LoggerFactory

import scala.concurrent.duration._

class HttpClient {

private val logger = LoggerFactory.getLogger(getClass)

private val client = EmberClientBuilder
.default[IO]
.build
Expand Down Expand Up @@ -61,6 +64,13 @@ class HttpClient {
)
val requestWithPayload = payload.fold(requestWithApiKey)(p => requestWithApiKey.withEntity(p))

client.use(_.expect[Json](requestWithPayload).attempt)
logger.debug(s"HTTP Request: ${requestWithPayload.toString()}")

val responseIO = client.use(_.expect[Json](requestWithPayload).attempt)

responseIO.map { response =>
logger.debug(s"HTTP Response: $response")
response
}
}
}

0 comments on commit 57d7823

Please sign in to comment.