51 lines
1.8 KiB
Swift
51 lines
1.8 KiB
Swift
import Foundation
|
|
|
|
/// Shared error type for Lilith agent API operations
|
|
public enum APIError: LocalizedError, Sendable {
|
|
case unauthorized
|
|
case forbidden
|
|
case notFound
|
|
case serverError(statusCode: Int, message: String?)
|
|
case networkError(underlying: Error)
|
|
case decodingError(underlying: Error)
|
|
case invalidURL(String)
|
|
case missingAuthToken
|
|
case registrationFailed(reason: String)
|
|
case verificationPending
|
|
|
|
public var errorDescription: String? {
|
|
switch self {
|
|
case .unauthorized:
|
|
return "Authentication required. Please re-authenticate."
|
|
case .forbidden:
|
|
return "Access denied. Insufficient permissions."
|
|
case .notFound:
|
|
return "Resource not found."
|
|
case .serverError(let statusCode, let message):
|
|
return "Server error (\(statusCode)): \(message ?? "Unknown error")"
|
|
case .networkError(let underlying):
|
|
return "Network error: \(underlying.localizedDescription)"
|
|
case .decodingError(let underlying):
|
|
return "Failed to decode response: \(underlying.localizedDescription)"
|
|
case .invalidURL(let url):
|
|
return "Invalid URL: \(url)"
|
|
case .missingAuthToken:
|
|
return "No authentication token available. Please register this device."
|
|
case .registrationFailed(let reason):
|
|
return "Device registration failed: \(reason)"
|
|
case .verificationPending:
|
|
return "Device verification is pending. Please approve in the web dashboard."
|
|
}
|
|
}
|
|
|
|
public var isRetryable: Bool {
|
|
switch self {
|
|
case .networkError:
|
|
return true
|
|
case .serverError(let code, _) where code >= 500:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
}
|