Add filter for failed get users requests

master
esensar 2016-10-04 01:38:29 +02:00
parent 5b2ff57d5d
commit 4acb04c4eb
1 changed files with 7 additions and 3 deletions

View File

@ -107,10 +107,16 @@ public class MainActivity extends AppCompatActivity {
return RestClient.getGitHubApi().getUsers(new Random().nextInt(1000)).execute().body();
} catch (IOException ioException) {
ioException.printStackTrace();
return new ArrayList<GitHubUser>();
return null;
}
}
})
.filter(new Func1<List<GitHubUser>, Boolean>() {
@Override
public Boolean call(List<GitHubUser> gitHubUsers) {
return gitHubUsers != null;
}
})
.subscribeOn(Schedulers.io()).
observeOn(AndroidSchedulers.mainThread());
@ -121,12 +127,10 @@ public class MainActivity extends AppCompatActivity {
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(List<GitHubUser> gitHubUsers) {
adapter.setItems(gitHubUsers);