From 733939269fd2da32eefe5d8a679697170e785376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Wed, 2 Sep 2026 19:03:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=88=86=E9=94=99=E8=AF=AF=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E8=AF=BB=E5=8F=96=E5=A4=B1=E8=B4=A5=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅将明确不存在的 OSS 或报告映射为 404 将请求无效、上游和 SpacetimeDB 故障映射为对应错误状态 --- .../crates/api-server/src/error_reports.rs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/server-rs/crates/api-server/src/error_reports.rs b/server-rs/crates/api-server/src/error_reports.rs index b57359e77..48315f849 100644 --- a/server-rs/crates/api-server/src/error_reports.rs +++ b/server-rs/crates/api-server/src/error_reports.rs @@ -3,6 +3,7 @@ use crate::{ api_response::json_success_body, auth::{AuthenticatedAccessToken, require_bearer_auth}, http_error::AppError, + platform_errors, request_context::RequestContext, state::AppState, tracking::{TrackingEventDraft, record_tracking_event_after_success}, @@ -273,7 +274,7 @@ pub async fn admin_get_error_report( .spacetime_client() .get_error_report(batch_id.clone()) .await - .map_err(|_| AppError::from_status(StatusCode::NOT_FOUND).with_message("报告不存在"))?; + .map_err(map_error_report_spacetime_error)?; let bytes = state .oss_client() .ok_or_else(|| internal("OSS 未配置"))? @@ -285,7 +286,7 @@ pub async fn admin_get_error_report( }, ) .await - .map_err(|_| AppError::from_status(StatusCode::NOT_FOUND).with_message("报告附件不存在"))?; + .map_err(map_error_report_oss_error)?; let (events, desc, logs) = parse_archive(&bytes).map_err(|e| internal(format!("报告归档损坏:{e}")))?; record_admin_report_audit( @@ -389,7 +390,7 @@ pub async fn admin_download_error_report( .spacetime_client() .get_error_report(batch_id.clone()) .await - .map_err(|_| AppError::from_status(StatusCode::NOT_FOUND).with_message("报告不存在"))?; + .map_err(map_error_report_spacetime_error)?; let bytes = state .oss_client() .ok_or_else(|| internal("OSS 未配置"))? @@ -401,7 +402,7 @@ pub async fn admin_download_error_report( }, ) .await - .map_err(|_| AppError::from_status(StatusCode::NOT_FOUND).with_message("报告附件不存在"))?; + .map_err(map_error_report_oss_error)?; record_admin_report_audit( &state, &ctx, @@ -429,6 +430,26 @@ fn bad_request(m: impl Into) -> AppError { fn internal(e: E) -> AppError { AppError::from_status(StatusCode::INTERNAL_SERVER_ERROR).with_message(e.to_string()) } + +fn map_error_report_oss_error(error: platform_oss::OssError) -> AppError { + match error.kind() { + platform_oss::OssErrorKind::ObjectNotFound => { + AppError::from_status(StatusCode::NOT_FOUND).with_message("报告附件不存在") + } + platform_oss::OssErrorKind::InvalidRequest => { + AppError::from_status(StatusCode::BAD_REQUEST).with_message("报告附件读取请求无效") + } + _ => platform_errors::map_oss_error(error, "error-report"), + } +} + +fn map_error_report_spacetime_error(error: spacetime_client::SpacetimeClientError) -> AppError { + if error.to_string() == "错误报告不存在" { + AppError::from_status(StatusCode::NOT_FOUND).with_message("报告不存在") + } else { + internal(error) + } +} async fn record_admin_report_audit( state: &AppState, ctx: &RequestContext,