Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RequestError conform LocalizedError? #264

Open
TienVu-PW opened this issue Jul 12, 2018 · 2 comments
Open

Make RequestError conform LocalizedError? #264

TienVu-PW opened this issue Jul 12, 2018 · 2 comments

Comments

@TienVu-PW
Copy link

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

@pcantrell
Copy link
Member

pcantrell commented Jul 13, 2018

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.

@TienVu-PW
Copy link
Author

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.

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

No branches or pull requests

2 participants