From cb42e46f0fd628dce119b3d965796dc0531cb1cb Mon Sep 17 00:00:00 2001 From: kdletters <61648117+kdletters@users.noreply.github.com> Date: Mon, 5 Oct 2026 16:58:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E7=95=99=E9=94=99=E8=AF=AF=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E6=8F=90=E4=BA=A4=E7=9A=84=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E6=AD=A3=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 保留错误报告 HTTP code、message 与安全响应片段 --- .../src-tauri/src/error_report/submit.rs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/error_report/submit.rs b/apps/ai-game-creator-shell/src-tauri/src/error_report/submit.rs index 33f6cb46f..96a0692b1 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/error_report/submit.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/error_report/submit.rs @@ -12,7 +12,7 @@ use reqwest::StatusCode; use serde_json::Value; use sha2::{Digest, Sha256}; use shared_contracts::error_reports::{CreateErrorReportBatchRequest, ErrorReportLogInput, Event}; -use std::time::Duration; +use std::{path::Path, time::Duration}; use url::Url; const HTTP_TIMEOUT: Duration = Duration::from_secs(60); @@ -78,13 +78,28 @@ fn response_error(status: StatusCode, body: &str) -> String { let detail = serde_json::from_str::(body) .ok() .and_then(|value| { - value - .get("error") - .and_then(|error| error.get("message")) + let error = value.get("error").unwrap_or(&value); + error + .get("message") .and_then(Value::as_str) .map(str::trim) .filter(|value| !value.is_empty()) .map(ToString::to_string) + .or_else(|| { + error + .get("code") + .and_then(Value::as_str) + .map(str::to_string) + }) + .or_else(|| serde_json::to_string(error).ok()) + }) + .or_else(|| { + let detail = crate::agent::redact_agent_runtime_error( + Path::new("__agc_no_project_root__"), + body.trim(), + 600, + ); + (!detail.trim().is_empty()).then_some(detail) }) .unwrap_or_else(|| format!("HTTP {}", status.as_u16())); format!("错误报告提交失败:{detail}") @@ -92,7 +107,7 @@ fn response_error(status: StatusCode, body: &str) -> String { fn response_data(body: &str) -> Result { let value: Value = serde_json::from_str(body) - .map_err(|_| "错误报告提交失败:响应不是合法 JSON".to_string())?; + .map_err(|error| format!("错误报告提交失败:响应不是合法 JSON:{error}"))?; Ok(value.get("data").cloned().unwrap_or(value)) }