From 67eb1eca8ba70978795581687d4013dfe2366031 Mon Sep 17 00:00:00 2001 From: Kirill Kamakin Date: Thu, 22 Dec 2022 18:43:18 +0100 Subject: [PATCH] Simplify getBaseUrl method --- .../mealient/datasource/impl/BaseUrlInterceptor.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/impl/BaseUrlInterceptor.kt b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/impl/BaseUrlInterceptor.kt index 8796804..ad00f26 100644 --- a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/impl/BaseUrlInterceptor.kt +++ b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/impl/BaseUrlInterceptor.kt @@ -38,6 +38,11 @@ class BaseUrlInterceptor @Inject constructor( private fun getBaseUrl() = runBlocking { val url = serverUrlProvider.getUrl() ?: throw IOException("Base URL is unknown") - url.runCatching { toHttpUrl() }.recover { throw IOException(it.message, it) }.getOrThrow() + url.runCatching { + toHttpUrl() + }.fold( + onSuccess = { it }, + onFailure = { throw IOException(it.message, it) }, + ) } } \ No newline at end of file