Since you are using RxJava, onError
is called in case of network errors and endpoints related error are part of the Response
.
In case of error, check if the throwable is an instance of HttpException
public void onError(Throwable e) {
if (e instanceof HttpException) {
if the check is true, the you have an error in your request. Cast the throwable to HttpException
, and access is members. E.g.
((HttpException) e).response().errorBody()
if the check is false
then you have a network related error.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…