siesta icon indicating copy to clipboard operation
siesta copied to clipboard

Make `RequestError` conform `LocalizedError`?

Open TienVu-PW opened this issue 7 years ago • 2 comments

It's sometimes a pain to import Siesta just to use RequestError's userMessage, I think can make it conform to LocalizedError and return userMessage as errorDescription, then we can get the message like common NSError/Error via localizedDescription

TienVu-PW avatar Jul 12 '18 05:07 TienVu-PW

Have you considered adding retroactive conformance yourself?

import Siesta

extension RequestError: LocalizedError {
    public var errorDescription: String? {
        return userMessage
    }
}

You can do that within your project, without any changes to Siesta.

If that doesn’t suit your needs, would you elaborate a bit on your use case? What is the situation in which you have a RequestError but are not working with any other Siesta API?

I’ve been reluctant to make RequestError a Swift Error because it doesn’t exactly have the shape of one. (It isn’t ever thrown, for starters.) It’s perhaps better to think of it as an event payload that wraps a Swift error.

That may be a distinction without a difference, and I’m open to adding LocalizedError conformance. However, I suspect that may cause more confusion than not: Siesta.RequestError has one guaranteed message; LocalizedError has four optional ones.

pcantrell avatar Jul 13 '18 21:07 pcantrell

Yes, that's what I'm doing atm, just thinking it might be more global usage for others, I'm actually doing verification inside the function that have Siesta call, that have completion closure with single error param that can return either Siesta error or verification error, then read the localized description to display it, don't need to cares if its from verification or networking.

Usually in iOS I only need to use error.localizedDescription to display for any kind of error, I think it will be more common use of Error inside the app. It's still kind of depends for others.

TienVu-PW avatar Jul 20 '18 04:07 TienVu-PW