I wrote an article about how can we create custom ...
# android
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 getTopic(): NetworkResponse<Topic, TopicError>
}

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
👍 4
👏 6