bugger/Sources/Services/Feishu/FeishuError.swift

37 lines
1.4 KiB
Swift

import Foundation
enum FeishuError: Error, LocalizedError {
case unauthorized
case networkError(Error?)
case apiError(code: Int, message: String)
case decodingError(Error, rawBody: String? = nil)
case notConfigured
case missingCredentials
case invalidConfiguration(String)
case paginationLimitExceeded
var errorDescription: String? {
switch self {
case .unauthorized:
return "Feishu authorization expired. Please re-authenticate."
case .networkError(let error):
return "Network error: \(error?.localizedDescription ?? "Unknown")"
case .apiError(let code, let message):
return "Feishu API error (\(code)): \(message)"
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:
return "Feishu app credentials are missing. Set FEISHU_APP_ID and FEISHU_APP_SECRET."
case .invalidConfiguration(let detail):
return "Invalid Feishu configuration: \(detail)"
case .paginationLimitExceeded:
return "Feishu table has too many records to load in one pass."
}
}
}