Skip to content
This repository has been archived by the owner on Jan 20, 2019. It is now read-only.

怎么使用? #2

Open
MichleMin opened this issue Dec 14, 2016 · 2 comments
Open

怎么使用? #2

MichleMin opened this issue Dec 14, 2016 · 2 comments

Comments

@MichleMin
Copy link

您好,博主,请问一下新版本的Redes 怎么像 老版本的swift 2.2版本一样,通过拓展 Responseable 协议,把业务错误,解析错误,网络错误都抛到 Result 的 failure 里面?

@cuzv
Copy link
Owner

cuzv commented Dec 14, 2016

Result 里面的错误现在被归纳为 RedesError 类型了。
如果你需要像以前一样都返回 NSError 的实例的话,写个扩展就好了。
参考下面的方式:

extension RedesError {
    /// A localized message describing what error occurred.
    public var nserror: NSError {
        switch self {
        case .internalFailed(reason: let reason):
            return reason as NSError
        case .parseFailed(reason: _):
            return NSErrorFrom(message: "解析数据失败")
        case .businessFailed(reason: let reason):
            return NSErrorFrom(message: reason.message)
        }
    }
}

@gulullu
Copy link

gulullu commented Feb 25, 2017

awesome!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants