From ba56b2385ead76b754b0af882dd9438f2927b620 Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Mon, 29 Jun 2026 00:26:15 +0800 Subject: [PATCH] debug: switch to print() for critical path, manual JSON body print() goes to stdout which is always visible in Xcode console regardless of log level filtering. Also replaced JSONEncoder with manual JSON string construction to rule out any Encodable issues with [String: String]. All critical send() calls now use print() instead of os.Logger. Co-Authored-By: Claude --- .../Services/Feishu/FeishuAuthService.swift | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Sources/Services/Feishu/FeishuAuthService.swift b/Sources/Services/Feishu/FeishuAuthService.swift index ff45cd4..13b3361 100644 --- a/Sources/Services/Feishu/FeishuAuthService.swift +++ b/Sources/Services/Feishu/FeishuAuthService.swift @@ -42,20 +42,20 @@ final class FeishuAuthService { } func exchangeCode(_ code: String) async throws -> OAuthTokenData { - BuggerLog.info("exchangeCode: start, code len=\(code.count)") + print("[BUGGER] exchangeCode: start, code len=\(code.count)") let tenantToken = try await tenantAccessToken() - BuggerLog.info("exchangeCode: got tenant token, building request...") + print("[BUGGER] exchangeCode: got tenantToken=\(tenantToken.prefix(8))..., building request...") let url = URL(string: "\(baseURL)/authen/v1/oidc/access_token")! var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type") request.setValue("Bearer \(tenantToken)", forHTTPHeaderField: "Authorization") - BuggerLog.info("exchangeCode: encoding body...") - let body: [String: String] = ["grant_type": "authorization_code", "code": code] - request.httpBody = try JSONEncoder().encode(body) - BuggerLog.info("exchangeCode: body encoded (\(request.httpBody?.count ?? 0)B), sending...") + // Use manual JSON to rule out JSONEncoder issues + let jsonBody = "{\"grant_type\":\"authorization_code\",\"code\":\"\(code)\"}" + request.httpBody = jsonBody.data(using: .utf8) + print("[BUGGER] exchangeCode: sending to \(url.absoluteString)...") let tokenData: OAuthTokenData = try await send(request) - BuggerLog.info("exchangeCode: got token access=\(tokenData.accessToken.prefix(8))... refresh=\(tokenData.refreshToken?.prefix(8) ?? "nil")...") + print("[BUGGER] exchangeCode: SUCCESS access=\(tokenData.accessToken.prefix(8))... refresh=\(tokenData.refreshToken?.prefix(8) ?? "nil")...") return tokenData } @@ -118,35 +118,32 @@ final class FeishuAuthService { } private func send(_ request: URLRequest) async throws -> T { - BuggerLog.info("→ \(request.httpMethod ?? "?") \(request.url?.absoluteString ?? "?")") + print("[BUGGER] → \(request.httpMethod ?? "?") \(request.url?.absoluteString ?? "?")") if let body = request.httpBody, let bodyStr = String(data: body, encoding: .utf8) { - BuggerLog.info(" body: \(bodyStr)") - } - if let auth = request.value(forHTTPHeaderField: "Authorization") { - BuggerLog.info(" auth: \(auth.prefix(20))...") + print("[BUGGER] body: \(bodyStr)") } let (data, response) = try await session.data(for: request) guard let httpResponse = response as? HTTPURLResponse else { - BuggerLog.error("← not an HTTP response") + print("[BUGGER] ← not an HTTP response") throw FeishuError.networkError(nil) } let bodyStr = String(data: data, encoding: .utf8) ?? "" - BuggerLog.info("← \(httpResponse.statusCode) \(bodyStr.prefix(500))") + print("[BUGGER] ← \(httpResponse.statusCode) \(bodyStr.prefix(500))") if httpResponse.statusCode == 401 { - BuggerLog.error("← 401 Unauthorized") + print("[BUGGER] ← 401 Unauthorized") throw FeishuError.unauthorized } do { let decoded = try decoder.decode(T.self, from: data) - BuggerLog.info(" decoded as \(T.self) ✓") + print("[BUGGER] decoded as \(T.self) ✓") return decoded } catch { - BuggerLog.error(" decode failed: \(error.localizedDescription)") - BuggerLog.error(" raw body: \(bodyStr.prefix(1000))") + print("[BUGGER] decode FAILED: \(error)") + print("[BUGGER] raw body: \(bodyStr.prefix(1000))") throw FeishuError.decodingError(error) } }