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

Support custom error types #583

Merged
merged 2 commits into from
Jan 7, 2024
Merged

Support custom error types #583

merged 2 commits into from
Jan 7, 2024

Conversation

matt-ramotar
Copy link
Collaborator

Hello :spock-hand: ! Does someone have any guidance/sample project on how to handle network/http errors with Store? Currently the network layer in our Android app takes care of catching exceptions, parsing error payloads and returning a custom monad class like Result<NetworkError, T>> . Looking at StoreReadResponse it seems that using Throwable or String is the only way to go. Thanks for your answers!

https://kotlinlang.slack.com/archives/C06007Z01HU/p1699457424194509

@matt-ramotar
Copy link
Collaborator Author

@digitalbuddha We would need to fix tests obviously but I wanted to get something up first for discussion. Adding a generic to StoreReadResponse and FetcherResult would introduce breaking changes I know we don't want. Thoughts?

@borsini
Copy link

borsini commented Nov 8, 2023

@matt-ramotar thanks for bringing up implementation ideas so quickly. Would it be possible for the Custom error to accept any type instead of only Throwable? As an example, our network layer uses a sealed interface with no Throwable inheritance. Something like this

sealed interface NetworkError { 
    data class StatusCodeError(val statusCode: Int, val error: CustomApiError?) : NetworkError
    data class UnknownError(val throwable: Throwable) : NetworkError
    data object NetworkUnavailableError : NetworkError
}

@matt-ramotar
Copy link
Collaborator Author

@borsini Seems fine to me 👍🏽

Copy link
Collaborator

@yigit yigit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but we should add a test ideally :)

@borsini borsini mentioned this pull request Dec 18, 2023
10 tasks
@borsini
Copy link

borsini commented Dec 18, 2023

Hello @matt-ramotar, I checked how this PR was doing and came up with an idea. I created this little draft PR to illustrate my thinking. What if, instead of having a sealed hierarchy, Store use only one generic Error type.

Let me know what you think 😄

@matt-ramotar
Copy link
Collaborator Author

Sorry to be slow @borsini, will try to get this merged by end of week

@borsini
Copy link

borsini commented Jan 5, 2024

No worries @matt-ramotar this is open source 🙂

Signed-off-by: mramotar <mramotar@dropbox.com>
Signed-off-by: mramotar <mramotar@dropbox.com>
@matt-ramotar matt-ramotar marked this pull request as ready for review January 7, 2024 20:21
@matt-ramotar matt-ramotar merged commit 912a390 into main Jan 7, 2024
2 of 3 checks passed
@matt-ramotar matt-ramotar deleted the error branch January 8, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants