使用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());
}
}
}
答案 0 :(得分:3)
CompositeException
。
确保您的错误处理代码没有抛出任何异常。
通常堆栈跟踪的根本原因在CompositeException
下方,前缀为Caused by
。