change: Log each response

This commit is contained in:
2024-01-18 10:21:32 +01:00
parent 899380ee27
commit 5427a81658
2 changed files with 6 additions and 6 deletions
@@ -38,7 +38,7 @@ class BahnApiService(
val time = LocalTime.of(hourAtDay.hour.value, 0) val time = LocalTime.of(hourAtDay.hour.value, 0)
val day = hourAtDay.date.format(dateFormatter) val day = hourAtDay.date.format(dateFormatter)
val hour = time.format(timeFormatter) val hour = time.format(timeFormatter)
val bahnErrorHandler = BahnErrorHandler() val responseLogger = BahnResponseLogger()
val response = restClient.get() val response = restClient.get()
.uri("https://apis.deutschebahn.com/db-api-marketplace/apis/timetables/v1/plan/" + .uri("https://apis.deutschebahn.com/db-api-marketplace/apis/timetables/v1/plan/" +
"${eva.value}/${day}/${hour}") "${eva.value}/${day}/${hour}")
@@ -49,8 +49,8 @@ class BahnApiService(
it.set("DB-Api-Key", properties.clientSecret) it.set("DB-Api-Key", properties.clientSecret)
} }
.retrieve() .retrieve()
.onStatus(bahnErrorHandler) .onStatus(responseLogger)
log.debug { "Response from DB API, station [${eva.value}], date [$day], hour [$hour], response [$response]" } log.debug { "Response from DB API, station [${eva.value}], date [$day], hour [$hour]" }
val body = response.body(BahnTimetable::class.java) val body = response.body(BahnTimetable::class.java)
body!!.eva = eva body!!.eva = eva
return body return body
@@ -4,13 +4,13 @@ import mu.KotlinLogging
import org.springframework.http.client.ClientHttpResponse import org.springframework.http.client.ClientHttpResponse
import org.springframework.web.client.ResponseErrorHandler import org.springframework.web.client.ResponseErrorHandler
class BahnErrorHandler : ResponseErrorHandler { class BahnResponseLogger : ResponseErrorHandler {
override fun hasError(response: ClientHttpResponse): Boolean { override fun hasError(response: ClientHttpResponse): Boolean {
return response.statusCode.isError return true
} }
override fun handleError(response: ClientHttpResponse) { override fun handleError(response: ClientHttpResponse) {
log.debug { "Error response: $response" } log.debug { "Response: $response" }
} }
companion object { companion object {