且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误处理程序不要求承诺

更新时间:2023-10-11 20:40:40

默认情况下,error不处理取消错误,而错误的凭据恰恰是取消错误.如果将print(e.cancelled)放在reject(e)之前,则会看到它将返回true.例如,如果输入错误的URL,则会收到false.为了解决这个问题,只需替换

By default error does not handle cancellation errors and bad credentials is exactly a cancellation error. If you put print(e.cancelled) before reject(e), you will see that it will return true. If you give a wrong URL for example, you will receive false. In order to get around this, just replace

}.error { error in

具有:

}.error(policy: .AllErrors) { error in

然后将触发

error.如果使用recover,默认情况下将处理取消错误.您可以检查 https://github.com/mxcl/PromiseKit/blob/master/Sources/Promise.swift#L367 了解更多信息.

and error will be triggered then. In case you use recover, cancellation errors will be handled by default. You can check https://github.com/mxcl/PromiseKit/blob/master/Sources/Promise.swift#L367 for more information.