sockeqwe / Model-View-Intent-Android

A demo that shows how to apply Model-View-Intent on Android
http://hannesdorfmann.com/android/model-view-intent
86 stars 11 forks source link

Question about handling error on MVI #1

Closed lenguyenthanh closed 8 years ago

lenguyenthanh commented 8 years ago

Firstly, I want to thank you for your awesome blog about MVI. I learned from it a lot. I'm trying to working on MVI pattern on real project. and I have face a problem with handling error. I don't know where to put this question so I create an issue here, hope it's on correct place.

MVI model works really beautiful. But I have a problem when an error is occurred, data stream will be ended. So we need some how (maybe onError() ) to recreate data stream and it breaks our cycle. Do you have any idea about this problem.

Thanks!

sockeqwe commented 8 years ago

Hi, you are not alone, there is a general misunderstanding what onError() should be used for.

onError() should only be used if an error has occurred so that the observable stream should be shut down, because it was an irreparable error.

This is typically not the case in MVI. Usually, an error (i.e. no internet connection) is just a "state" of the model, so I typically use onErrorReturn() or onExceptionResumeNext( ) and the subscriber's onNext() gets the model with "error state"

Here are more operator for error handling: https://github.com/ReactiveX/RxJava/wiki/Error-Handling-Operators

lenguyenthanh commented 8 years ago

Thank you for your answer. I found out the solution for this.

lenguyenthanh commented 8 years ago

Sorry bother you again. I think I'm facing the same problem with this guy here. Could you take a look at it? Thanks!

sockeqwe commented 8 years ago

Sorry, but you are on your own here. It really depends on what exactly you want to do. Maybe some Subject will be helpful.

lenguyenthanh commented 8 years ago

Okay, I think investigate more. Thank you so much.