2017-01-25 7 views
0

私はretrofitでObservableコールを持っていますが、3つのAPIコールを圧縮しました しかし、3つのコールをまとめたいのですが、いつか1つのコールが失敗します。私のために必須で、残りの呼び出しはオプションです。なぜなら、それらのうちの1つがエラーで失敗すると、それが欲しくないからです。もしJoinObservable.when(OperatorJoinPatterns.or(call1、call2))があれば私は考えていました。その後、 だけの事はあり、それはあなたのロジックを破るようメーリングリストでzipオペレータでObservableをオプションにする

Observable.zip(getSearchObservable(FIRST_PAGE), App.getApi().allbookmarks(), SpotlightUtil.getSpotLightBanner(), App.getApi().getFollowingSuggestions(AppConfigUtil.getFollowingSuggestions().getLimit()), 
       (searchResult, myFavouritesResults, spotlightListResult, followingSuggestionsResult) -> combineCall(searchResult, myFavouritesResults, spotlightListResult, followingSuggestionsResult, false)) 
       .observeOn(AndroidSchedulers.mainThread()) 
       .doOnNext(spotlightsAndSearchResultAndSuggestionsResult -> { 
//my main call that i want if that fail the request should fail 
        if (!NetUtils.isServerOk(spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().getStatus())) { 
         throw new ServerErrorException(spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().getErrorMessage()); 
        } 

        if (spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().posts.size() < PAGE_SIZE) { 
         rvPosts.setFinished(true); 
        } 
        hideLoader(); 
        mPostAdapter.mSuggestions = spotlightsAndSearchResultAndSuggestionsResult.getFollowingSuggestionsResult().getSuggestion(); 
        checkToAddOrRemoveFeedbackSpotLight(spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().posts, true); 
            }) 
       .doOnError(throwable -> { 
        ErrorScreenUtils.checkError(throwable, this, true); 
        hideLoader(); 
       }) 
       .retryWhen(RxActivity.RETRY_CONDITION).compose(bindUntilEvent(FragmentEvent.DESTROY)) 
       .subscribe(); 

答えて

1

doOnErrorは、エラーの伝播を停止しません。

オプションのソースには、onErrorResumeNext,onErrorReturnItemonErrorReturnのいずれかの演算子を使用します。エラーをダミーの値に置き換えることができます。zip ped:

Observable.zip(
    source1, 
    source2, 
    optionalSource3.onErrorReturnItem(stub) 
) 
... 
+0

私のコードでは例として表示できますか? –

関連する問題