Hello. What’s best practice on how to handle error...
# multiplatform
j
Hello. What’s best practice on how to handle errors for a multi-platform library that serves as an API client? Thoughts so far: 1. Expose suspend functions that return successful responses as data classes. These functions can throw errors. 2. Return
kotlin.Result
p
2
but I would prefer my own Result sealed class. That could be Success(data) and Error(ErrorInfo)/Error (Throwable)
k
Arrow is another option https://arrow-kt.io/
kotlin.Result
is kinda half baked, not too great… Plus
runCatching: Result
is bad for using with coroutines cause it swallows cancellation exceptions
j
Which is better for this use case.. arrow or https://github.com/michaelbull/kotlin-result
And can I provide both options to users.. the plain suspend funtions and the result implementation
k
p
Provide a basic api that serves only suspend functions or the use cases that fetch the network stuff and then provide(in a separate artifact), extra wrappers for the desired result library of customers choice. The problem with including a third party in the basic implementation is that your client might be using another Result library and will pollute their namespace