I am looking for a tutorial showing how to handle ...
# android
k
I am looking for a tutorial showing how to handle multiple error types from retrofit. I'm currently using "Either" style types (one for Successs & Error each) but our APIs seems to have different json formats for different errors so I need a way to handle them in form of Sealed Class type. I found ZachSweers'
moshi-sealed
extension might help in this scenario but I'm afraid I won't be having any "type" parameter in the json which is required for
moshi-sealed
. Any tutorial hinting different approaches would also work.
j
I don't know about moshi-sealed, but kotlin serialization has support for polymorphism. So you can create your sealed class with all the subclasses for your current network errors and add one more, called for example, unknown, so using it as default when the backend sends an error body which it doesn't fit to your current error subclasses.
k
Great! Which Kotlin version do I need to use kotlinx serialization?
j
Yeah