From 8286c81afb6f4fac87ac0b604a325ab5e300a519 Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Thu, 2 Jul 2026 10:02:02 +0800 Subject: [PATCH] WIP:feat: capture and log raw response body in Feishu decoding error for better debugging --- Sources/Services/Feishu/FeishuError.swift | 9 ++++++--- Sources/Services/Feishu/FeishuService.swift | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/Services/Feishu/FeishuError.swift b/Sources/Services/Feishu/FeishuError.swift index 6ead02c..0f10347 100644 --- a/Sources/Services/Feishu/FeishuError.swift +++ b/Sources/Services/Feishu/FeishuError.swift @@ -4,7 +4,7 @@ enum FeishuError: Error, LocalizedError { case unauthorized case networkError(Error?) case apiError(code: Int, message: String) - case decodingError(Error) + case decodingError(Error, rawBody: String? = nil) case notConfigured case missingCredentials @@ -16,8 +16,11 @@ enum FeishuError: Error, LocalizedError { return "Network error: \(error?.localizedDescription ?? "Unknown")" case .apiError(let code, let message): return "Feishu API error (\(code)): \(message)" - case .decodingError: - return "Failed to parse Feishu response. Field mappings may be incorrect." + case .decodingError(let error, let rawBody): + if let rawBody { + return "Failed to parse Feishu response: \(rawBody)" + } + return "Failed to parse Feishu response. Field mappings may be incorrect. (\(error.localizedDescription))" case .notConfigured: return "Feishu table not configured. Open Settings." case .missingCredentials: diff --git a/Sources/Services/Feishu/FeishuService.swift b/Sources/Services/Feishu/FeishuService.swift index debe2e3..cf35e86 100644 --- a/Sources/Services/Feishu/FeishuService.swift +++ b/Sources/Services/Feishu/FeishuService.swift @@ -78,6 +78,10 @@ final class FeishuService { guard let httpResponse = response as? HTTPURLResponse else { throw FeishuError.networkError(nil) } + + let rawBody = String(data: data, encoding: .utf8) ?? "" + BuggerLog.debug("fetchPage: HTTP \(httpResponse.statusCode) body=\(String(rawBody.prefix(500)))") + if httpResponse.statusCode == 401 { throw FeishuError.unauthorized } @@ -86,7 +90,9 @@ final class FeishuService { do { apiResponse = try decoder.decode(FeishuAPIResponse.self, from: data) } catch { - throw FeishuError.decodingError(error) + BuggerLog.error("fetchPage: decode FAILED: \(error)") + BuggerLog.error("fetchPage: raw body: \(String(rawBody.prefix(1000)))") + throw FeishuError.decodingError(error, rawBody: String(rawBody.prefix(200))) } guard apiResponse.code == 0, let pageData = apiResponse.data else {