Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling #16

Closed
ffgiraldez opened this issue Apr 14, 2018 · 0 comments
Closed

Better error handling #16

ffgiraldez opened this issue Apr 14, 2018 · 0 comments
Assignees

Comments

@ffgiraldez
Copy link
Owner

ffgiraldez commented Apr 14, 2018

Handle gracefully connectivity errors, especially when no data available offline.

Define a ComicError sealed class with 2 branches NetworkError and EmptyError

the idea is that QueryViewModel.results property now will be an LiveData<Either<ComicError,T>> instead of LiveData<T>, create a new ViewState QueryViewState.Error that contains a ComicError now on UI implementation handle it accordingly, for suggestions, for example, could be

@BindingAdapter("suggestions")
fun bindSuggestions(search: FloatingSearchView, liveData: List<Either<ComicError,String>?) = liveData?.let { 
    when (it) {
        is Left -> QuerySearchSuggestion(it.a.toHumanError())
        is Rigth -> it.b.map { QuerySearchSuggestion(it) }
    }.let { search.swapSuggestions(it) }
}

fun ComicError.toHumanError(): String = when(this) {
    is NetworkError -> "no internet conection"
    is EmptyError -> "search without results"
}

the search feature will be a more "harder" as the UI change, when a ComicError happens, the list could be hidden and display an icon with text that change based on it, as properties could be observed by more than one observer, actual @BindingAdapter will update adapter on Right values and hide the list on Left one, and create a new one to the error view that update the text/icon on Left values and hide it on Right

@ffgiraldez ffgiraldez self-assigned this May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant