leosan
11/23/2018, 12:46 PMCase: I have to fetch from api (if fails)> from cache (if fails) -> catrastrophic failure handling
So first case would be something like
Using lambdas
fun getContent(){
launch{
try{
val content =useCase.getContent(errorLambdaCallback= {handleError(it)})
showContent(content)
} catch(e:Exception){
handleError(e)
}
}
}
Or use channels to communicate back that some error happened but the cache is retrieved?
or there is actually a better way to handle this case where I need to handle error and get the contenthalley
11/23/2018, 1:11 PMleosan
11/23/2018, 1:22 PMleosan
11/23/2018, 1:24 PMsuspend fun getContent(erroCallback: (error:Throwable) -> Unit): Content {
runCatching { apiService.getBalance().await() }
.onSuccess { cache.set("key", it.content) }
.onFailure { erroCallback.invoke(it) }
return Content(cache.get("key",, "0"), "")
halley
11/23/2018, 1:28 PMhalley
11/23/2018, 1:30 PMleosan
11/23/2018, 1:33 PMleosan
11/23/2018, 1:34 PMleosan
11/23/2018, 1:36 PMleosan
11/23/2018, 1:40 PMhalley
11/23/2018, 1:43 PMleosan
11/23/2018, 1:45 PMhalley
11/23/2018, 1:47 PM