I’m using this for basically all of my viewModels- is there a more concise/kotlinesque way to write the coroutine + error handling + networking logic, and should I be using a specific dispatcher for networking?
Copy code
fun updateUserLang(user: UpdateUser) {
viewModelScope.launch {
try {
val lang = repository.updateUser(user).data.attributes!!.locale
_networkCallSuccess.postValue(Pair(lang!!, true))
} catch (e: HttpException) {
println("error: ${e.localizedMessage}")
}
}
}
d
Dominaezzz
09/16/2019, 10:50 PM
You can add a coroutine exception handler to the scope's context.
s
scottiedog45
09/17/2019, 1:58 PM
That’s definitely interesting - I don’t understand the advantage though.