我有一个服务,当我输入错误的登录凭据时会失败。但是,我的Promise错误处理程序不会被调用。
我似乎不明白我的代码有什么问题,所以
error
永远不会到达回调。
服务
func loadRepositories() -> Promise<[Repository]>{
return Promise { fullfill, reject in
manager.request(Method.GET, baseURL + "/api/1.0/user/repositories")
.authenticate(user: username, password: password)
.responseArray { (response: Response<[Repository], NSError>) in
switch response.result{
case .Success(let value):
fullfill(value)
case .Failure(let e):
// The breakpoint here is reached.
reject(e)
}
}
}
}
搬运
firstly{
service!.loadRepositories()
}.then { repositories -> Void in
loginVC.dismissViewControllerAnimated(true, completion: nil)
self.onLoginSuccessful()
}.always{
// Always gets called
loginVC.isSigningIn = false
}.error { error in
// I never get here even though `reject(e)` is called from the service.
loginVC.errorString = "Login went wrong"
}