fix(kis): CurrentPriceResponse의 output 필드 null 허용 및 KIS API 에러 응답 파싱 예외 해결
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user