Compare commits
2 Commits
d34984d480
...
9b99d9c1ff
| Author | SHA1 | Date |
|---|---|---|
|
|
9b99d9c1ff | |
|
|
8286c81afb |
|
|
@ -4,7 +4,7 @@ enum FeishuError: Error, LocalizedError {
|
||||||
case unauthorized
|
case unauthorized
|
||||||
case networkError(Error?)
|
case networkError(Error?)
|
||||||
case apiError(code: Int, message: String)
|
case apiError(code: Int, message: String)
|
||||||
case decodingError(Error)
|
case decodingError(Error, rawBody: String? = nil)
|
||||||
case notConfigured
|
case notConfigured
|
||||||
case missingCredentials
|
case missingCredentials
|
||||||
|
|
||||||
|
|
@ -16,8 +16,11 @@ enum FeishuError: Error, LocalizedError {
|
||||||
return "Network error: \(error?.localizedDescription ?? "Unknown")"
|
return "Network error: \(error?.localizedDescription ?? "Unknown")"
|
||||||
case .apiError(let code, let message):
|
case .apiError(let code, let message):
|
||||||
return "Feishu API error (\(code)): \(message)"
|
return "Feishu API error (\(code)): \(message)"
|
||||||
case .decodingError:
|
case .decodingError(let error, let rawBody):
|
||||||
return "Failed to parse Feishu response. Field mappings may be incorrect."
|
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:
|
case .notConfigured:
|
||||||
return "Feishu table not configured. Open Settings."
|
return "Feishu table not configured. Open Settings."
|
||||||
case .missingCredentials:
|
case .missingCredentials:
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,10 @@ final class FeishuService {
|
||||||
guard let httpResponse = response as? HTTPURLResponse else {
|
guard let httpResponse = response as? HTTPURLResponse else {
|
||||||
throw FeishuError.networkError(nil)
|
throw FeishuError.networkError(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let rawBody = String(data: data, encoding: .utf8) ?? "<binary \(data.count)B>"
|
||||||
|
BuggerLog.debug("fetchPage: HTTP \(httpResponse.statusCode) body=\(String(rawBody.prefix(500)))")
|
||||||
|
|
||||||
if httpResponse.statusCode == 401 {
|
if httpResponse.statusCode == 401 {
|
||||||
throw FeishuError.unauthorized
|
throw FeishuError.unauthorized
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +90,9 @@ final class FeishuService {
|
||||||
do {
|
do {
|
||||||
apiResponse = try decoder.decode(FeishuAPIResponse<RecordListData>.self, from: data)
|
apiResponse = try decoder.decode(FeishuAPIResponse<RecordListData>.self, from: data)
|
||||||
} catch {
|
} 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 {
|
guard apiResponse.code == 0, let pageData = apiResponse.data else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue