I am using Retrofit 2.6.0 with coroutines for my web service call. I am getting the API response properly with all response codes (success & error cases). My Issue is when I
You can just add a CoroutineExceptionHandler
to handle the error for you:
In your ViewModel:
val coroutineExceptionHandler = CoroutineExceptionHandler{_, t -> {
t.printStackTrace()
showErrorOrSomething()
}}
viewModelScope.launch(Dispatchers.IO + coroutineExceptionHandler) {
val apiResponse = ApiConnectionBridge.getHomeUiDetails(SharedPrefUtils.getAuthToken(context))
if (apiResponse.isSuccessful) {
// success case
} else {
// error case
}
}