Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Djaler committed Jul 9, 2024
1 parent 2e29cb5 commit 2087200
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package com.github.djaler.evilbot.config

import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpSend
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.api.createClientPlugin
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logging
import io.ktor.client.plugins.plugin
import io.ktor.client.statement.bodyAsText
import io.ktor.client.statement.request
import io.ktor.http.ContentType
import io.ktor.serialization.jackson.JacksonConverter
import io.sentry.Breadcrumb
Expand All @@ -20,7 +21,7 @@ import org.springframework.context.annotation.Configuration
class RestConfig {
@Bean
fun httpClient(objectMapper: ObjectMapper): HttpClient {
return HttpClient {
val httpClient = HttpClient {
install(ContentNegotiation) {
register(ContentType.Any, JacksonConverter(objectMapper))
}
Expand All @@ -33,6 +34,24 @@ class RestConfig {

install(SentryPlugin)
}
httpClient.plugin(HttpSend).intercept { request ->
val originalCall = execute(request)

originalCall.response.bodyAsText()

Sentry.addBreadcrumb(
Breadcrumb.http(
request.url.toString(),
request.method.value
).apply {
setData("content", originalCall.response.bodyAsText())
}
)

originalCall
}

return httpClient
}
}

Expand All @@ -47,16 +66,4 @@ val SentryPlugin = createClientPlugin("SentryPlugin") {
}
)
}

onResponse {response ->
val request = response.request
Sentry.addBreadcrumb(
Breadcrumb.http(
request.url.toString(),
request.method.value
).apply {
setData("response", response.bodyAsText())
}
)
}
}

0 comments on commit 2087200

Please sign in to comment.