保留错误报告提交的服务端正文
保留错误报告 HTTP code、message 与安全响应片段
This commit is contained in:
@@ -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::<Value>(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<Value, String> {
|
||||
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))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user