stefano
12/09/2022, 3:55 PMval oas = specs.map {
async {
try {
client.get(it).body<OpenApiSpec>() // Ktor HTTP client
} catch (e: ClientRequestException) {
null
}
}
}.awaitAll()
I'd like to abstract away the exception handling, so I've tried something like this:
suspend inline fun <reified T> HttpResponse.bodyOrNull(): T? = try {
body()
} catch (e: ClientRequestException) {
null
}
val oas = specs.map {
async {
client.get(it).bodyOrNull<OpenApiSpec>()
}
}.awaitAll()
But instead of swallowing the exceptions and returning null as in the example above, I get the exception bubbling up. I suspect I'm not yet fully understanding the exception handling model for coroutines, could anybody help shed some light? Thanks in advance.
(Btw, I obtain the same result if I wrap the try/catch with coroutineScope
)stefano
12/09/2022, 10:44 PMget()
throwing an exception, not body()
so it makes sense that my refactoring has no effect