From d74ce4bb2a9b652cde1d8f31d278f929d94a89a3 Mon Sep 17 00:00:00 2001 From: Kirill Kamakin Date: Wed, 21 Dec 2022 22:36:16 +0100 Subject: [PATCH] Improve Base URL interceptor error reporting --- .../kirmanak/mealient/datasource/impl/BaseUrlInterceptor.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 4b40e26..b64ae1f 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 @@ -4,7 +4,7 @@ import gq.kirmanak.mealient.datasource.LocalInterceptor import gq.kirmanak.mealient.datasource.ServerUrlProvider import gq.kirmanak.mealient.logging.Logger import kotlinx.coroutines.runBlocking -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Interceptor import okhttp3.Response import java.io.IOException @@ -37,6 +37,7 @@ class BaseUrlInterceptor @Inject constructor( } private fun getBaseUrl() = runBlocking { - serverUrlProvider.getUrl()?.toHttpUrlOrNull() ?: throw IOException("Base URL is unknown") + val url = serverUrlProvider.getUrl() ?: throw IOException("Base URL is unknown") + url.runCatching { toHttpUrl() }.recover { throw IOException(it) }.getOrThrow() } } \ No newline at end of file