import Foundation enum ConnectionAttemptDecision: Equatable { case retryNode case stop case revokeAuthorization } enum ConnectionAttemptPolicy { static func decide(error: Error, hasAssignedNode: Bool) -> ConnectionAttemptDecision { if error is CancellationError { return .stop } if let failure = error as? UCVLError { switch failure { case .api(let status, _): return status == 401 || status == 403 ? .revokeAuthorization : .stop case .vpnPermission, .invalidConfiguration, .invalidResponse: // Permission, malformed local configuration and control-plane // failures must not mark every otherwise healthy node as failed. return .stop case .connection: break } } return hasAssignedNode ? .retryNode : .stop } }