问题
I'm using Retrofit 2.0 along with RxJava and I need to make a custom error handler so that I can get the HTTP error code. This is the example that I get, but it won't work on Retrofit 2.0, since RetrofitError is removed.
@Override
public void onError(Throwable e) {
if (e instanceof RetrofitError) {
if (((RetrofitError) e).isNetworkError()) {
//handle network error
} else {
//handle error message from server
}
}
}
Is there any way that I can do this? Thanks.
回答1:
I'm sorry that I didn't read the documentation carefully, so I just find a simple answer that works
@Override
public void onError(Throwable e) {
HttpException exception = (HttpException) e;
Toast.makeText(getApplicationContext(), exception.code() + "", Toast.LENGTH_SHORT).show();
}
来源:https://stackoverflow.com/questions/33074927/retrofit-2-0-rxjava-custom-error-handler