From fefeb36802c89f4989e95a4a9c2ff5f9d76f7bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Fri, 21 Oct 2022 22:58:56 +0200 Subject: [PATCH] feat(spine): Log detailed information about HTTP failures --- .../kotlin/opensavvy.spine.ktor.server/Server.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spine-ktor/spine-ktor-server/src/commonMain/kotlin/opensavvy.spine.ktor.server/Server.kt b/spine-ktor/spine-ktor-server/src/commonMain/kotlin/opensavvy.spine.ktor.server/Server.kt index 4af8563..4dd5daf 100644 --- a/spine-ktor/spine-ktor-server/src/commonMain/kotlin/opensavvy.spine.ktor.server/Server.kt +++ b/spine-ktor/spine-ktor-server/src/commonMain/kotlin/opensavvy.spine.ktor.server/Server.kt @@ -5,6 +5,8 @@ import io.ktor.server.application.* import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* +import opensavvy.logger.Logger.Companion.warn +import opensavvy.logger.loggerFor import opensavvy.spine.Operation import opensavvy.spine.Parameters import opensavvy.spine.ktor.NetworkResponse @@ -13,6 +15,10 @@ import opensavvy.state.Status import opensavvy.state.firstResult import opensavvy.state.state +object Server { + val log = loggerFor(this) +} + /** * Builds a route to match the specified [operation]. * @@ -104,11 +110,15 @@ inline fun error("The server did not find any value to return, this should not be possible") is Status.StandardFailure -> { + Server.log.warn(data.kind, data.message, data.cause?.stackTraceToString()) { "Failed request" } val code = data.kind.toHttp() call.respond(code, data.message ?: "No message") } - is Status.Failed -> call.respond(HttpStatusCode.InternalServerError, data.message ?: "No message") + is Status.Failed -> { + Server.log.warn(data.message, data.stackTraceToString()) { "Failed request" } + call.respond(HttpStatusCode.InternalServerError, data.message ?: "No message") + } } } } -- 2.51.2