diff --git a/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt b/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt index 748dd76..03fc64a 100644 --- a/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt +++ b/src/main/kotlin/com/github/djaler/evilbot/config/RestConfig.kt @@ -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 @@ -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)) } @@ -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 } } @@ -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()) - } - ) - } }