I am using the following:
- Alamofire (3.1.4)
- PromiseKit (3.0.0)
- xCode Version 7.2.1 (7C1002)
I am rejecting an Alamofire request with the custom error below:
Error
is the struct that provides convenience methods for creating custom alamofire NSErrors. I am using errorWithCode
as shown below.
let error = Error.errorWithCode(Error.Code.InputStreamReadFailed, failureReason: "reason")
reject(error)
I have also tried the following:
reject(NSError(domain: "somedomain", code: 123, userInfo: [:]))
In either case I receive the following message in the xCode console: "...PromiseKit: Unhandled Error: Error Domain=com.alamofire.error Code=-6000 "reason" UserInfo={NSLocalizedFailureReason=reason}"
I am wondering if this is something I am doing wrong on my end or a bug?
Here is the complete function:
func getImageByID(imageID : String) -> Promise<UIImage> {
return Promise { fulfill, reject in
Alamofire.request(.GET, getImageURL(imageID)).responseData {response in
if response.result.isSuccess {
if response.data != nil {
if let image = UIImage(data: response.data!) {
fulfill(image)
} else if UIImage(data: response.data!) == nil {
let error = Error.errorWithCode(Error.Code.InputStreamReadFailed, failureReason: "reason")
reject(error)
//reject(NSError(domain: "somedomain", code: 123, userInfo: [:]))
//reject(NSError(domain: "somedomain", code: 123, userInfo: nil))
} else {
.....
}
}
} else {
reject(response.result.error!)
}
}
}
}
Any help is most appreciated!
Thanks!