Thursday, 14 October 2021

RxJava: How to update value of List in onErrorResumeNext

I'm trying to update the validate the list and update the value accordingly but when I'm getting an error, the process gets stopped. I'm calling it in ViewModel class as:

fun validateList(list: List<Model>): Single<List< Model >> {
    return Observable.fromIterable(list)
        .toFlowable(BackpressureStrategy.LATEST)
        .flatMapSingle { validate() }
        .toList()
        .map { list.mapIndexed { index, testModel ->  
               (if (it[index] != null) {
                testModel.isVerified = it[index].toString()
                 } else throw Exception("ERROR")); testModel }
       }
        .onErrorResumeNext { error -> }

And I'm calling it from fragment as:

private fun verify() {
    showLoading(true)
    testViewModel.validateList(arrayList)
        .doFinally {
            showLoading(false)
        }
        .asyncToUiSingle()
        .subscribe({
            adjustCard(it)
        }, {
            it.printStackTrace()
        })
        .addTo(disposables)
}

TestModel:

 data class TestModel(
    val title: String,
    var isVerified: String? = null,
    var reason: String? = null )

Please help me to understand how I can update value of reason field in list if one element gets failed status and continue the validations for other elements.



from RxJava: How to update value of List in onErrorResumeNext

No comments:

Post a Comment