Labdb: debug logging — register payload + HTTP 응답 body 출력
INTERNAL_ERROR(500) 원인 좁히기 위해 LabdbClient에 logcat 추가: - POST /devices/register 보내는 정확한 payload (TAG=LabdbClient) - 모든 응답의 HTTP code + raw body (앞 500자) - IOException 발생 시 스택 trace logcat 필터: tag:LabdbClient Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package com.example.medilightv2android.services.labdb
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.example.medilightv2android.ble.BleManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -43,6 +44,7 @@ data class UploadResult(
|
||||
* 모든 메서드는 suspend, IO 디스패처에서 실행.
|
||||
*/
|
||||
object LabdbClient {
|
||||
private const val TAG = "LabdbClient"
|
||||
private const val BASE = "https://labdb.medithings.net/api/v1"
|
||||
private const val APP_NAME = "VesiScan"
|
||||
private val JSON = "application/json; charset=utf-8".toMediaType()
|
||||
@@ -66,6 +68,7 @@ object LabdbClient {
|
||||
ble.serialNumber.value.takeIf { it.isNotEmpty() }?.let { put("serialNumber", it) }
|
||||
put("appVersion", appVersion)
|
||||
}
|
||||
Log.d(TAG, ">> POST /devices/register payload=$body")
|
||||
val req = Request.Builder()
|
||||
.url("$BASE/devices/register")
|
||||
.post(body.toString().toRequestBody(JSON))
|
||||
@@ -157,10 +160,12 @@ object LabdbClient {
|
||||
return try {
|
||||
client.newCall(req).execute().use { res ->
|
||||
val raw = res.body?.string().orEmpty()
|
||||
Log.d(TAG, "<< ${req.method} ${req.url.encodedPath} → HTTP ${res.code} body=${raw.take(500)}")
|
||||
val obj = if (raw.isBlank()) JSONObject() else runCatching { JSONObject(raw) }.getOrElse { JSONObject() }
|
||||
res.code to obj
|
||||
}
|
||||
} catch (t: IOException) {
|
||||
Log.w(TAG, "exec failed: ${req.method} ${req.url}", t)
|
||||
throw LabdbNetworkError(t)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user