Last active
March 30, 2016 07:35
-
-
Save Qata/82a28a552d5d527b4c16b344872b000b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sendCommand(command: RpcCommand, controller: ControlNode) -> SignalProducer<AnyObject, RpcControllerError> { | |
self.mac = controller.mac | |
let (method, params) = command.rpcTuple | |
return self.sendCommand(method, withParams: params).toSignalProducer() | |
.ignoreNil() | |
.map { $0["result"] } | |
.mapError { (error: NSError) -> RpcControllerError in | |
switch error.domain { | |
case NSPOSIXErrorDomain: | |
switch Int32(error.code) { | |
case ETIMEDOUT: | |
return .TimedOut(error.localizedDescription) | |
case ECONNREFUSED, ECONNABORTED, ENETUNREACH: | |
return .NetworkError(error.localizedDescription, error.code) | |
default: break | |
} | |
case RPCErrorDomain: | |
return .RpcError(error.localizedDescription, error.code) | |
case NSCocoaErrorDomain: | |
return .JsonError(error.localizedDescription) | |
default: break | |
} | |
return .UnknownError(error.localizedDescription, error.code) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment