mirror of
https://github.com/2martens/tsw-timetable.git
synced 2026-10-17 07:57:55 +02:00
change: Log each response
This commit is contained in:
+3
-3
@@ -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
|
||||||
|
|||||||
+3
-3
@@ -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 {
|
||||||
Reference in New Issue
Block a user