APP崩溃:致命异常:io.reactivex.exceptions.CompositeException

时间:2017-12-05 08:30:31

标签: android retrofit2 reactivex

使用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());
        }
    }
}

1 个答案:

答案 0 :(得分:3)

当你的错误处理程序在处理流中抛出的错误时抛出异常时,通常会抛出

CompositeException

确保您的错误处理代码没有抛出任何异常。

通常堆栈跟踪的根本原因在CompositeException下方,前缀为Caused by