-
Notifications
You must be signed in to change notification settings - Fork 48
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
Card: Remove try/catch from Vault Flow #303
Conversation
Are you going to do this for all the API calls? It's an interesting pattern. I'm thinking about this for iOS. But I see that's similar to what you are doing here. You have try/catch block that returns a result type. I think you had mentioned that you were going to remove listener pattern eventually. |
@KunJeongPark yes for Kotlin it's considered a best practice. Honestly I'm not sure this will be needed for iOS though. Swift does have checked exceptions i.e. when you call code that |
val errorDescription = "Error loading resource with id $resId." | ||
val ioError = PayPalSDKError(0, errorDescription, reason = e) | ||
LoadRawResourceResult.Failure(ioError) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it throw other exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. I took a thorough tour of the docs and here are all the methods called:
- Context#getResources() does not throw
- Resources#openRawResource()
throws Resources.NotFoundException
- InputStream#available()
throws IOException
- ByteArray() does not throw
- InputStream#read()
throws IOException, NullPointerException
- InputStream#close()
throws IOException
According to the docs InputStream#read()
will only throw if resAsBytes
is null
, and through Kotlin we have guarantees that it is non-null. All the other possible exceptions we've caught.
5e57637
to
ba94513
Compare
Summary of changes
try/catch
fromCardClient.vault()
UpdateSetupTokenResult
to make it a sealed class with.Success
and.Failure
subclassesChecklist
Added a changelog entryAuthors