From 3925d0d5ad55d96d24adc446a5188d58c11ef965 Mon Sep 17 00:00:00 2001 From: xRain Date: Tue, 18 Aug 2026 02:26:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A0=E6=95=88=20Token=20=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=20/config=20500=E2=80=94=E2=80=94getLogin=20?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5=E8=BF=94=E5=9B=9E=20None?= =?UTF-8?q?=20=E8=80=8C=E9=9D=9E=E6=8A=9B=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SimApiAuth.getLogin:JSON 无效/非对象时返回 None(视为 token 无效), 不再抛 JsonException(Fail to convert to JsonObject) - 新增 parseLoginItemSafe 私有辅助,删除旧 parseLoginItem - 复现:带无效 Token 的 POST /config 之前 500,现在 200 正常 - 验证:无效/有效 Token、GET/POST /config 均正常,日志无 Fail to convert --- cjpm.lock | 12 ++++++------ src/helpers/SimApiAuth.cj | 16 ++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cjpm.lock b/cjpm.lock index ffec643..8954596 100644 --- a/cjpm.lock +++ b/cjpm.lock @@ -5,15 +5,15 @@ version = 0 soulsoft_extensions_options = {version = "1.0.20260528"} redis = {version = "1.0.20260627"} soulsoft_serialization = {version = "1.0.20260528"} - soulsoft_web_http = {version = "1.0.20260528"} soulsoft_identity_claims = {version = "1.0.20260528"} - soulsoft_web_routing = {version = "1.0.20260528"} - soulsoft_extensions_hosting = {version = "1.0.20260528"} - soulsoft_extensions_logging = {version = "1.0.20260528"} soulsoft_web_cors = {version = "1.0.20260528"} + soulsoft_extensions_hosting = {version = "1.0.20260528"} + soulsoft_web_mvc = {version = "1.0.20260528"} + soulsoft_extensions_logging = {version = "1.0.20260528"} soulsoft_extensions_logging_console = {version = "1.0.20260528"} soulsoft_extensions_configuration = {version = "1.0.20260528"} + soulsoft_web_routing = {version = "1.0.20260528"} soulsoft_extensions_injection = {version = "1.0.20260528"} - soulsoft_extensions_logging_configuration = {version = "1.0.20260528"} soulsoft_web_hosting = {version = "1.0.20260528"} - soulsoft_web_mvc = {version = "1.0.20260528"} + soulsoft_extensions_logging_configuration = {version = "1.0.20260528"} + soulsoft_web_http = {version = "1.0.20260528"} diff --git a/src/helpers/SimApiAuth.cj b/src/helpers/SimApiAuth.cj index c546b1d..f5ba7fb 100644 --- a/src/helpers/SimApiAuth.cj +++ b/src/helpers/SimApiAuth.cj @@ -157,11 +157,20 @@ public class SimApiAuth { } } return match (json) { - case Some(j) => Some(parseLoginItem(j)) + case Some(j) => parseLoginItemSafe(j) case None => None } } + /// 解析登录信息;JSON 无效/非对象时返回 None(视为 token 无效,对齐 C# 返回 null) + private static func parseLoginItemSafe(json: String): ?SimApiLoginItem { + try { + Some(JsonSerializer.Deserialize(json)) + } catch (_: Exception) { + None + } + } + /** * 获取某用户全部登录信息。 * @param userId 用户 ID。 @@ -288,9 +297,4 @@ public class SimApiAuth { // 统一 JSON 序列化:对齐 .NET JsonSerializer.Serialize(item) JsonSerializer.Serialize(item) } - - private static func parseLoginItem(json: String): SimApiLoginItem { - // 统一 JSON 反序列化:对齐 .NET JsonSerializer.Deserialize(json) - JsonSerializer.Deserialize(json) - } }