From c06c24d8bcbe966da9f444fde9cf4898f5c9d512 Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Mon, 29 Jun 2026 23:33:53 +0900 Subject: [PATCH] =?UTF-8?q?fix(kis-api):=20Null=20reference=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EA=B0=95=ED=99=94=20(=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=EC=B2=98=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KisApiClient.TryGetAccessTokenAsync()의 null 참조 경고 제거. - 토큰 응답 본문 존재 여부 검증 - TryGetValue 기반 안전한 파싱 - access_token 필수 필드 검증 Build: 0 errors, 0 warnings ✅ Co-Authored-By: Claude Haiku 4.5 --- .../Services/KisApiClient.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dotnet/QuantEngine.Infrastructure/Services/KisApiClient.cs b/src/dotnet/QuantEngine.Infrastructure/Services/KisApiClient.cs index 2873c69..678b356 100644 --- a/src/dotnet/QuantEngine.Infrastructure/Services/KisApiClient.cs +++ b/src/dotnet/QuantEngine.Infrastructure/Services/KisApiClient.cs @@ -174,8 +174,15 @@ public class KisApiClient : IKisApiClient response.EnsureSuccessStatusCode(); var tokenData = await response.Content.ReadFromJsonAsync>(); - var accessToken = tokenData["access_token"]?.ToString() ?? throw new InvalidOperationException("No access_token in response"); - var expiresInStr = tokenData.ContainsKey("expires_in") ? tokenData["expires_in"]?.ToString() : "86400"; + if (tokenData == null) throw new InvalidOperationException("Token response body is empty"); + + if (!tokenData.TryGetValue("access_token", out var tokenObj) || tokenObj == null) + throw new InvalidOperationException("No access_token in response"); + var accessToken = tokenObj.ToString()!; + + var expiresInStr = tokenData.TryGetValue("expires_in", out var expiresObj) && expiresObj != null + ? expiresObj.ToString() + : "86400"; var expiresInSec = int.TryParse(expiresInStr, out var seconds) ? seconds : 86400; var expiresAt = DateTime.UtcNow.AddSeconds(expiresInSec);