I am using Retrofit 2.0.1. I want to handle all types of network errors and exceptions (like no network connection ,timeout error,server not found etc.) I have found this link. But some of the methods were deprecated in v1.8.0. How can I do that in 2.0.1?
9. How to handle error in the destructor? Explanation: It will not throw an exception from the destructor but it will the process by using terminate() function. 10.
Think of Call as a simple class which wraps your API response and you need this class make an API call and provide listeners/callback to notify you with error and response , although if you use kotlin coroutines then after version 2.6.
If you need centeralize error handler take a look at this thread But if you just need a simple error handler you can do:
@Override
public void onFailure(Throwable throwable) {
if (throwable instanceof HttpException) {
// We had non-2XX http error
}
if (throwable instanceof IOException) {
// A network or conversion error happened
}
// We don't know what happened. We need to simply convert to an unknown error
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With