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 <noreply@anthropic.com>
This commit is contained in:
parent
f61f8332b8
commit
ba56b2385e
|
|
@ -42,20 +42,20 @@ final class FeishuAuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
func exchangeCode(_ code: String) async throws -> OAuthTokenData {
|
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()
|
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")!
|
let url = URL(string: "\(baseURL)/authen/v1/oidc/access_token")!
|
||||||
var request = URLRequest(url: url)
|
var request = URLRequest(url: url)
|
||||||
request.httpMethod = "POST"
|
request.httpMethod = "POST"
|
||||||
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
|
||||||
request.setValue("Bearer \(tenantToken)", forHTTPHeaderField: "Authorization")
|
request.setValue("Bearer \(tenantToken)", forHTTPHeaderField: "Authorization")
|
||||||
BuggerLog.info("exchangeCode: encoding body...")
|
// Use manual JSON to rule out JSONEncoder issues
|
||||||
let body: [String: String] = ["grant_type": "authorization_code", "code": code]
|
let jsonBody = "{\"grant_type\":\"authorization_code\",\"code\":\"\(code)\"}"
|
||||||
request.httpBody = try JSONEncoder().encode(body)
|
request.httpBody = jsonBody.data(using: .utf8)
|
||||||
BuggerLog.info("exchangeCode: body encoded (\(request.httpBody?.count ?? 0)B), sending...")
|
print("[BUGGER] exchangeCode: sending to \(url.absoluteString)...")
|
||||||
let tokenData: OAuthTokenData = try await send(request)
|
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
|
return tokenData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,35 +118,32 @@ final class FeishuAuthService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func send<T: Decodable>(_ request: URLRequest) async throws -> T {
|
private func send<T: Decodable>(_ 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) {
|
if let body = request.httpBody, let bodyStr = String(data: body, encoding: .utf8) {
|
||||||
BuggerLog.info(" body: \(bodyStr)")
|
print("[BUGGER] body: \(bodyStr)")
|
||||||
}
|
|
||||||
if let auth = request.value(forHTTPHeaderField: "Authorization") {
|
|
||||||
BuggerLog.info(" auth: \(auth.prefix(20))...")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let (data, response) = try await session.data(for: request)
|
let (data, response) = try await session.data(for: request)
|
||||||
guard let httpResponse = response as? HTTPURLResponse else {
|
guard let httpResponse = response as? HTTPURLResponse else {
|
||||||
BuggerLog.error("← not an HTTP response")
|
print("[BUGGER] ← not an HTTP response")
|
||||||
throw FeishuError.networkError(nil)
|
throw FeishuError.networkError(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
let bodyStr = String(data: data, encoding: .utf8) ?? "<binary \(data.count)B>"
|
let bodyStr = String(data: data, encoding: .utf8) ?? "<binary \(data.count)B>"
|
||||||
BuggerLog.info("← \(httpResponse.statusCode) \(bodyStr.prefix(500))")
|
print("[BUGGER] ← \(httpResponse.statusCode) \(bodyStr.prefix(500))")
|
||||||
|
|
||||||
if httpResponse.statusCode == 401 {
|
if httpResponse.statusCode == 401 {
|
||||||
BuggerLog.error("← 401 Unauthorized")
|
print("[BUGGER] ← 401 Unauthorized")
|
||||||
throw FeishuError.unauthorized
|
throw FeishuError.unauthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let decoded = try decoder.decode(T.self, from: data)
|
let decoded = try decoder.decode(T.self, from: data)
|
||||||
BuggerLog.info(" decoded as \(T.self) ✓")
|
print("[BUGGER] decoded as \(T.self) ✓")
|
||||||
return decoded
|
return decoded
|
||||||
} catch {
|
} catch {
|
||||||
BuggerLog.error(" decode failed: \(error.localizedDescription)")
|
print("[BUGGER] decode FAILED: \(error)")
|
||||||
BuggerLog.error(" raw body: \(bodyStr.prefix(1000))")
|
print("[BUGGER] raw body: \(bodyStr.prefix(1000))")
|
||||||
throw FeishuError.decodingError(error)
|
throw FeishuError.decodingError(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue