【发布时间】:2016-03-30 12:29:20
【问题描述】:
我正在使用改造 2 和 rx java
情况: 该应用程序发送一些请求,然后我得到自动转换为用户 dto 的 json 格式的响应,然后在 rx java 的 onNext 方法中我收到用户列表。如果我从服务器收到这样的消息怎么办:{"error":"can't get the list of users"}
如何使用改造 2 和 rx 处理这种情况?
Subscription subscriptionBranches = model.getRepoBranches(owner, name)
.map(branchesMapper)
.subscribe(new Observer<List<Branch>>() {
@Override
public void onCompleted() {
;
}
@Override
public void onError(Throwable e) {
if (e instanceof retrofit.HttpException) {
HttpException exception = (HttpException) e;
}
showError(e);
}
@Override
public void onNext(List<Branch> list) {
branchList = list;
view.showBranches(list);
}
});
addSubscription(subscriptionBranches);
.....
@Override
public Observable<List<RepositoryDTO>> getRepoList(String name) {
return apiInterface
.getRepositories(name)
.compose(applySchedulers());
}
【问题讨论】: