These are chat archives for ReactiveX/RxJava

22nd
Mar 2018
defaultbr
@defaultbr
Mar 22 2018 19:16

Hello guys, i have some doubts about chaining operation base on result for example:

  checkCode(code)
                            .subscribeOn(scheduler.io())
                            .observeOn(scheduler.ui())
                            .subscribe(
                                    { response ->
                                        if (response.isSuccessful) {

                                        } else {
                                            handleErrorBody(response)
                                        }
                                    },
                                    { error ->
                                        handleError(error)
                                    })
            )

in the response.isSucessful i can extract the body from retrofit response and than save on database, but it will be in main thread (i know how to start another one observable or kotlin functions to do on back) but im trying to chain inside the Rx

My problem resides when i create a doOnNext and save:

                    checkCode(code)
                            .doOnNext({ it -> saveToDb(it)})
                            .subscribeOn(scheduler.io())
                            .observeOn(scheduler.ui())
                            .subscribe(
                                    { response ->
                                        if (response.isSuccessful) {
                                            view?.showDataSaved()
                                        } else {
                                            handleErrorBody(response)
                                        }
                                    },
                                    { error ->
                                        handleError(error)
                                    })
            )

and inside the handleError i check if which kind of exception was, is that correct? the exception thrown inside the savedToDb will be catch on subscribe exception or not? is this a good approach?

James Nelson
@JamesXNelson
Mar 22 2018 19:17
use triple `
defaultbr
@defaultbr
Mar 22 2018 19:17
done =)
thx