ich eine Lösung finden habe (OnErrorNotImplementedException when Interceptor throws.), aber ich habe noch OnErrorNotImplementedException
und SocketTimeoutException
und die App-Abstürze erhalten.Ich benutze rxjava2 + retrofit2 + okhttp3 in meiner Android-Anwendung und abgestürzt werden, wenn App nicht mit dem Internet verbunden
Mein Code HTTP Ergebnis zu handhaben:
observable.compose(TransformerHelper.<Response<T>>io_main()).doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Disposable disposable) throws Exception {
requestCallback.onBefore();
}
}).doOnError(new Consumer<Throwable>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
requestCallback.onAfter();
requestCallback.onError(throwable);
}
}).doOnComplete(new Action() {
@Override
public void run() throws Exception {
requestCallback.onAfter();
}
}).onErrorReturn(new Function<Throwable, Response<T>>() {
@Override
public Response<T> apply(@io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
return null;
}
}).subscribe(new Consumer<Response<T>>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Response<T> response) throws Exception {
try {
requestCallback.onAfter();
if (response.isSuccess()) {
requestCallback.onSuccess(response.data, response.msg);
} else {
requestCallback.onBizErr(response.code, response.msg);
}
} catch (Exception e) {
requestCallback.onAfter();
requestCallback.onError(e.getCause());
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
requestCallback.onAfter();
requestCallback.onError(throwable);
}
});
Wenn Sie Ihre Chancen auf eine Antwort erhöhen möchten, sollten Sie wahrscheinlich Ihre Stack-Trace einfügen. Warum gibst du null in 'onErrorReturn' zurück? 'null' hat keine isSuccess-Methode. – Lukasz