diff --git a/to-live-photo/to-live-photo/Analytics.swift b/to-live-photo/to-live-photo/Analytics.swift index 81fbcd8..805237b 100644 --- a/to-live-photo/to-live-photo/Analytics.swift +++ b/to-live-photo/to-live-photo/Analytics.swift @@ -133,8 +133,12 @@ final class Analytics { // 记录到统计 errorStats.record(code: appError.code, stage: appError.stage?.rawValue) } else { - // 通用错误 - let code = "UNKNOWN" + // 从通用错误中提取有用信息 + let nsError = error as NSError + let code = "\(nsError.domain):\(nsError.code)" + params["code"] = code + params["domain"] = nsError.domain + params["nsErrorCode"] = nsError.code errorStats.record(code: code, stage: nil) } diff --git a/to-live-photo/to-live-photo/AppState.swift b/to-live-photo/to-live-photo/AppState.swift index 5804b9f..b913856 100644 --- a/to-live-photo/to-live-photo/AppState.swift +++ b/to-live-photo/to-live-photo/AppState.swift @@ -168,13 +168,14 @@ final class AppState { } return nil } catch { + let appError = AppError(code: "LPB-901", message: "未知错误", underlyingErrorDescription: error.localizedDescription, suggestedActions: ["重试"]) await MainActor.run { self.isProcessing = false - self.processingError = AppError(code: "LPB-901", message: "未知错误", underlyingErrorDescription: error.localizedDescription, suggestedActions: ["重试"]) + self.processingError = appError self.currentWorkId = nil self.currentProcessingTask = nil } - Analytics.shared.logError(.buildLivePhotoFail, error: error) + Analytics.shared.logAppError(.buildLivePhotoFail, appError: appError) return nil } } diff --git a/to-live-photo/to-live-photo/Views/HomeView.swift b/to-live-photo/to-live-photo/Views/HomeView.swift index e8edce7..0939d26 100644 --- a/to-live-photo/to-live-photo/Views/HomeView.swift +++ b/to-live-photo/to-live-photo/Views/HomeView.swift @@ -9,6 +9,7 @@ import SwiftUI import PhotosUI import AVKit import Photos +import LivePhotoCore struct HomeView: View { @Environment(AppState.self) private var appState @@ -279,7 +280,12 @@ struct HomeView: View { errorMessage = String(format: format, error.localizedDescription) isLoading = false selectedItem = nil - Analytics.shared.logError(.importVideoFail, error: error) + let appError = AppError( + code: "IMP-001", + message: "视频导入失败", + underlyingErrorDescription: error.localizedDescription + ) + Analytics.shared.logAppError(.importVideoFail, appError: appError) } } }