sitepodmatt
02/28/2019, 10:20 AMclass RequestContextTest : StringSpec({
"playing with human context" {
runBlocking {
supervisorScope {
try {
val repoSize = async<String> {
// do remote
val somenestedOp = async<String> {
delay(100)
throw DomainException("oh no", Exception("400"))
}
somenestedOp.await()
}
repoSize.await()
} catch (de: DomainException) {
println("we will swallow")
}
}
}
println("we exited okay")
}
})
class DomainException(msg: String, t: Throwable) : Exception(msg, t)
leosan
02/28/2019, 10:22 AMval somenestedOp = async<String> {
delay(100)
throw DomainException("oh no", Exception("400"))
}
sitepodmatt
02/28/2019, 10:25 AMleosan
02/28/2019, 10:29 AMval somenestedOp = async<String> {
try{
someOperation()
}catch (de: DataException){
val mappedException = when(de){
is HttpException -> throw DomainException("oh no", Exception("400"))
is IOException -> throw OtherDomainException("oh no", Exception("300"))
}
throw mappedException()
}
}
sitepodmatt
02/28/2019, 10:32 AMleosan
02/28/2019, 10:32 AMsitepodmatt
02/28/2019, 10:35 AMleosan
02/28/2019, 10:39 AMrunCatching{}.recover{}
and it worked beautifully I was just wondering if it was a common thing rethrowing errors, I was used to Rx way of composing the upstream with transformers + onErrorResumeNextsitepodmatt
02/28/2019, 10:40 AMleosan
02/28/2019, 10:42 AM