From 56a496a3846884bb965608ea8eddc90b800eaa90 Mon Sep 17 00:00:00 2001 From: tapframe <85391825+tapframe@users.noreply.github.com> Date: Wed, 22 Jul 2026 14:47:53 +0530 Subject: [PATCH] chore(simkl): log sync HTTP responses --- .../app/features/simkl/SimklApiClient.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/simkl/SimklApiClient.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/simkl/SimklApiClient.kt index cac9481ad..a38306602 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/simkl/SimklApiClient.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/simkl/SimklApiClient.kt @@ -1,5 +1,6 @@ package com.nuvio.app.features.simkl +import co.touchlab.kermit.Logger import com.nuvio.app.features.addons.RawHttpResponse import com.nuvio.app.features.addons.httpRequestRaw import kotlinx.coroutines.CancellationException @@ -13,6 +14,8 @@ import kotlin.math.max import kotlin.random.Random private const val SIMKL_MAX_RESPONSE_BODY_BYTES = 8 * 1024 * 1024 +private const val SIMKL_RESPONSE_LOG_PREVIEW_CHARS = 2_048 +private val simklSyncLog = Logger.withTag("SimklSync") internal enum class SimklHttpMethod { GET, @@ -116,6 +119,12 @@ internal class SimklApiClient( continue } + logSyncReadResponse( + request = request, + response = response, + attempt = attempt + 1, + ) + when (classifySimklResponse(response.status, request.scrobbleStopConflictIsSuccess)) { SimklResponseAction.SUCCESS -> return@withLock response.toApiResponse() SimklResponseAction.SOFT_SUCCESS -> { @@ -169,6 +178,29 @@ internal class SimklApiClient( } } +private fun logSyncReadResponse( + request: SimklApiRequest, + response: RawHttpResponse, + attempt: Int, +) { + if (request.method != SimklHttpMethod.GET || !request.path.startsWith("/sync/")) return + + val preview = response.body + .take(SIMKL_RESPONSE_LOG_PREVIEW_CHARS) + .replace("\r", "\\r") + .replace("\n", "\\n") + .ifEmpty { "" } + val truncationMarker = if (response.body.length > SIMKL_RESPONSE_LOG_PREVIEW_CHARS) "…" else "" + val contentType = response.headers.headerValue("content-type") ?: "" + + simklSyncLog.i { + "Simkl HTTP response: method=${request.method} path=${request.path} " + + "query=${request.query} status=${response.status} attempt=$attempt " + + "contentType=$contentType bodyChars=${response.body.length} " + + "bodyPreview=$preview$truncationMarker" + } +} + internal object SimklApi { val client: SimklApiClient by lazy { SimklApiClient(