fix(kis): CurrentPriceResponse의 output 필드 null 허용 및 KIS API 에러 응답 파싱 예외 해결

This commit is contained in:
2026-11-18 17:42:47 +09:00
parent 681f64ea6b
commit 84c11c835e
2 changed files with 8 additions and 10 deletions
+4 -4
View File
@@ -249,10 +249,10 @@ data class ExecutionData(
@Serializable @Serializable
data class CurrentPriceResponse( data class CurrentPriceResponse(
val rt_cd: String, // 0: 성공, 0 이외: 실패 val rt_cd: String = "", // 0: 성공, 0 이외: 실패
val msg_cd: String, val msg_cd: String = "",
val msg1: String, val msg1: String = "",
val output: CurrentPriceOutput val output: CurrentPriceOutput? = null
) )
@Serializable @Serializable
+4 -6
View File
@@ -581,20 +581,18 @@ object KisTradeService {
if (response.status.isSuccess()) { if (response.status.isSuccess()) {
val body = response.body<CurrentPriceResponse>() val body = response.body<CurrentPriceResponse>()
if (body.rt_cd == "0") { if (body.rt_cd == "0" && body.output != null) {
// println("${body.output}")
Result.success(body.output) Result.success(body.output)
} else { } else {
println("API 에러: ${body.msg1}") println("⚠️ [KIS 현재가 조회 에러] [$stockCode] code: ${body.msg_cd}, msg: ${body.msg1}")
Result.failure(Exception("API 에러: ${body.msg1}")) Result.failure(Exception("API 에러: ${body.msg1} (code: ${body.msg_cd})"))
} }
} else { } else {
println("HTTP 에러: ${response.status}") println("HTTP 에러: ${response.status}")
Result.failure(Exception("HTTP 에러: ${response.status}")) Result.failure(Exception("HTTP 에러: ${response.status}"))
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() println("❌ [fetchCurrentPrice 예외] [$stockCode]: ${e.message}")
println("HTTP 에러: ${e.message}")
Result.failure(e) Result.failure(e)
} }
} }