I wrote an article about how can we create custom ...
# squarelibraries
a
I wrote an article about how can we create custom Retrofit CallAdapter to handle the API calls errors and success states. eg
Copy code
interface Service {
  @GET("topics/{id}")
  suspend fun topic(): NetworkResponse<Topic, CommentsError>
}

class Repository {
  val tpoic = service.getTopic()

    when (tpoic) {
      is NetworkResponse.Success -> // request succeded
      is NetworkResponse.ApiError -> // request failed
      is NetworkResponse.NetworkError -> // network error
      is NetworkResponse.UnknownError -> // unknown error happened
    }
}
https://medium.com/@melegy/create-retrofit-calladapter-for-coroutines-to-handle-response-as-states-c102440de37a
p
But how do you sanely compose many of these result style responses?
1
👍 1
g
would be interesting to see real life code written like this, I found that separate success/error is enough, because user-friendly error (with network errors, api errors) is anyway generated by other code, which handles all known cases and shows actual error And there checking for original throwable makes more sense, it does essentially the samw what your CallAdapter, but it looks unnecessary to do on level of retrofit adapter
1