import io.ktor.client.call.*
import io.ktor.client.request.*
class Greeting {
// ...
@Throws(Exception::class)
suspend fun greeting(): String {
val rockets: List<RocketLaunch> =
httpClient.get("https://api.spacexdata.com/v4/launches").body()
val lastSuccessLaunch = rockets.last { it.launchSuccess == true }
return "Guess what it is! > ${platform.name.reversed()}!" +
"\nThere are only ${daysUntilNewYear()} left until New Year! 🎆" +
"\nThe last successful launch was ${lastSuccessLaunch.launchDateUTC} 🚀"
}
}
refs: https://kotlinlang.org/docs/multiplatform-mobile-upgrade-app.html#connect-http-client https://zenn.dev/ktrueda/articles/kotlin-jvm-0006
Exceptionをスローするfunctionは
@Throws(Exception::class)
のようにアノテーションをつけたい。 これによりバイトコードレベルで functionにthrows Exception
が付与される。