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
data class CurrentPriceResponse(
val rt_cd: String, // 0: 성공, 0 이외: 실패
val msg_cd: String,
val msg1: String,
val output: CurrentPriceOutput
val rt_cd: String = "", // 0: 성공, 0 이외: 실패
val msg_cd: String = "",
val msg1: String = "",
val output: CurrentPriceOutput? = null
)
@Serializable
+4 -6
View File
@@ -581,20 +581,18 @@ object KisTradeService {
if (response.status.isSuccess()) {
val body = response.body<CurrentPriceResponse>()
if (body.rt_cd == "0") {
// println("${body.output}")
if (body.rt_cd == "0" && body.output != null) {
Result.success(body.output)
} else {
println("API 에러: ${body.msg1}")
Result.failure(Exception("API 에러: ${body.msg1}"))
println("⚠️ [KIS 현재가 조회 에러] [$stockCode] code: ${body.msg_cd}, msg: ${body.msg1}")
Result.failure(Exception("API 에러: ${body.msg1} (code: ${body.msg_cd})"))
}
} else {
println("HTTP 에러: ${response.status}")
Result.failure(Exception("HTTP 에러: ${response.status}"))
}
} catch (e: Exception) {
e.printStackTrace()
println("HTTP 에러: ${e.message}")
println("❌ [fetchCurrentPrice 예외] [$stockCode]: ${e.message}")
Result.failure(e)
}
}