Hi,
I am using Retrofit 2.6.2 and the latest version of coroutines. I am trying to throw an exception from an Interceptor and trying to catch it but each time it crashes the app. I am using the following app as an example https://github.com/harmittaa/KoinExample I modified the code to throw an exception in the AuthInterceptor.
I've tried a lot of different scopes such as the ones below however i am unable to catch the exception thrown from the interceptor and it crashes the app.
viewModelScope.launch(Dispatchers.IO) {
weather.postValue(Resource.loading(null))
try {
val data = weatherRepo.getWeather(input)
weather.postValue(data)
} catch (throwable : Throwable) {
}
}
viewModelScope.launch(Dispatchers.IO) {
weather.postValue(Resource.loading(null))
try {
val deferred = async {
weatherRepo.getWeather(input)
}
weather.postValue(deferred.await())
} catch (throwable : Throwable) {
}
}
var weather = location.switchMap { location ->
liveData(Dispatchers.IO) {
emit(Resource.loading(null))
try {
emit(weatherRepo.getWeather(location))
} catch (throwable : Throwable) {
}
}
}
The error was with the exception not extending IOException.
Most helpful comment
The error was with the exception not extending IOException.