Think of the different shapes your network respons...
# rx
a
Think of the different shapes your network response can take, and then map each shape to a member of a sealed class. For example:
Copy code
sealed class Response {
    data class Success(data: Data): Response()
    data class Error(code: Int, msg: String): Response()
}
Then, when you perform your retrofit action, you can map whatever happens to the appropriate response. The trick is to make sure an error never really enters the stream to begin with (as I believe it gets trickier since as soon as you send an error your original stream is going to terminate)
👍 1
v
I suppose some sort of generics could be used, because not all responses are returning
Data
, some are returning
MembershipDetails
, others -
PaymentResponse
a
sure, that’s easy enough to hide in the success type:
Copy code
sealed class Response {
    data class Success<T>(data: T): Response()
    data class Error(code: Int, msg: String): Response()
}