Ich erhalte immer eine nicht behandelte Ausnahme bei google + Antworten mit Fehlern jsonretrofit2.HttpException geworfen, obwohl es in onError behandelt wurde
retrofit2.HttpException: HTTP 404
at retrofit2.RxJavaCallAdapterFactory$SimpleCallAdapter$1.call(RxJavaCallAdapterFactory.java:159)
at retrofit2.RxJavaCallAdapterFactory$SimpleCallAdapter$1.call(RxJavaCallAdapterFactory.java:154)
at rx.internal.operators.OperatorMap$1.onNext(OperatorMap.java:54)
at retrofit2.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:109)
at retrofit2.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:88)
at rx.Observable$2.call(Observable.java:162)
at rx.Observable$2.call(Observable.java:154)
at rx.Observable$2.call(Observable.java:162)
at rx.Observable$2.call(Observable.java:154)
....
In diesem Code:
Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> strSub) {
// Getting ID
strSub.onNext(AccountUtils.getAccountId(appContext));
strSub.onCompleted();})
.subscribeOn(Schedulers.io())
// Get Google+ Image through Retrofit2
.flatMap(str -> createGPlusUserObservable(str, AccountUtils.ANDROID_API_KEY))
.map(this::setprofileImage) // I don't see Timber.d message inside that method!
.compose(binder)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(subscriber);
In createGPlusUserObservable Ich benutze Retrofit 2 bis google + Bild
private Observable<GPlusUser> createGPlusUserObservable(String userId, String apiKey) {
//try {
GoogleApiService service = ServiceFactory.getInstance().createJsonRetrofitService(
GoogleApiService.class,
GoogleApiService.SERVICE_ENDPOINT
);
Observable<GPlusUser> result = service.getGPlusUserInfo(userId, apiKey);
Timber.d("Here1!"); // I see that in console!
return result; // It always returns result!
/*} catch (Throwable e) { - it doesn't catch anything!
Timber.d("Here!");
}*/
}
Und Teilnehmer zu erhalten ist:
new Subscriber<GPlusUser>() {
@Override
public void onCompleted() {
Timber.d("GPlusUserSubscriber ON COMPLETED");
}
@Override
public void onError(Throwable e) {
if (e instanceof HttpException) {
Timber.d("RETROFIT!"); // I see that in console!
}
}
@Override
public void onNext(GPlusUser gPlusUser) {
setupAccountBox();
}
};
UPDATE: setprofileImage Methode
private GPlusUser setprofileImage(GPlusUser gPlusUser) {
Timber.d("FOUR"); // As I've said, it doesn't appear in console
AccountUtils.setProfileImage(appContext, gPlusUser.image.url);
Timber.d("Setting profile image: %s", gPlusUser.image.url);
return gPlusUser;
}
So ist die Frage - warum immer ich bin nicht behandelte Ausnahme, wenn ich es in Teilnehmer onError (Throwable e)
Dank Griff!
Könnten Sie den Code für 'setprofileImage 'posten? – JohnWowUs
Siehe UPDATE. Vielen Dank! – blinker