From 675dfe0c8f22032e1e96cbe4177ee9b9f9fdda80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 2 Oct 2026 22:08:44 +0800 Subject: [PATCH] =?UTF-8?q?account=5Fapi=20=E6=8A=BD=E5=87=BA=20error=5Ffi?= =?UTF-8?q?eld=20=E6=B6=88=E9=99=A4=20message/code=20=E7=9A=84=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit error_message / error_code 只差字段名,合并到 error_field(body, field) 调用点保留 error_message / error_code 两个薄封装 --- .../src-tauri/src/account_api.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/account_api.rs b/apps/ai-game-creator-shell/src-tauri/src/account_api.rs index a8a05391d..9c2caee3e 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/account_api.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/account_api.rs @@ -67,26 +67,23 @@ fn bounded_business_id(value: &str, label: &str) -> Result { Ok(value.to_string()) } -fn error_message(body: &str) -> Option { +fn error_field(body: &str, field: &str) -> Option { let value = serde_json::from_str::(body).ok()?; let error = value.get("error").unwrap_or(&value); error - .get("message") + .get(field) .and_then(Value::as_str) .map(str::trim) - .filter(|message| !message.is_empty()) + .filter(|detail| !detail.is_empty()) .map(ToString::to_string) } +fn error_message(body: &str) -> Option { + error_field(body, "message") +} + fn error_code(body: &str) -> Option { - let value = serde_json::from_str::(body).ok()?; - let error = value.get("error").unwrap_or(&value); - error - .get("code") - .and_then(Value::as_str) - .map(str::trim) - .filter(|code| !code.is_empty()) - .map(ToString::to_string) + error_field(body, "code") } fn map_http_error(status: StatusCode, body: &str, fallback: &str) -> String {