【发布时间】:2017-12-05 08:30:31
【问题描述】:
使用retrofit 我调用API 来获取列表,但是当没有找到数据时,我调用onErrorGetOccasion 方法并得到HttpException,为此我按照代码所示处理它。
现在我的问题有时是在onErrorGetOccasion 方法中我得到了致命的
Exception: io.reactivex.exceptions.CompositeException this error and app crash.
对此有何建议?
//Get Occasion API
private void callGetOccasionAPI(String pageIndex, boolean isDialogShown) {
if (NetworkUtils.isConnected()) {
if (mPageCount == 1 && isDialogShown)
showProgressDialog(mContext);
RetrofitAdapter.createRetroServiceWithSessionToken(mContext)
.getOccasion(pageIndex)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onSuccessGetOccasion, this::onErrorGetOccasion);
} else {
SnackBarUtils.defaultSnackBar(getString(R.string.error_no_internet), mRootView);
}
}
private void onErrorGetOccasion(Throwable throwable) {
hideProgressDialog();
if (throwable instanceof HttpException) {
ResponseBody body = ((HttpException) throwable).response().errorBody();
Utils.setLog(body != null ? body.toString() : null);
try {
if (body != null) {
if (body.string().contains(mContext.getString(R.string.msg_event_not_found))) {
if (mPageCount == 1) {
mTxtRecordNotFound.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.INVISIBLE);
}
} else {
SnackBarUtils.errorSnackBar(getString(R.string.error_api), mRootView, null);
}
}
} catch (IOException e) {
e.printStackTrace();
Crashlytics.log(e.getMessage());
}
}
}
【问题讨论】:
标签: android retrofit2 reactivex