Improve Base URL interceptor error reporting

This commit is contained in:
Kirill Kamakin
2022-12-21 22:36:16 +01:00
parent 04474c3055
commit d74ce4bb2a

View File

@@ -4,7 +4,7 @@ import gq.kirmanak.mealient.datasource.LocalInterceptor
import gq.kirmanak.mealient.datasource.ServerUrlProvider import gq.kirmanak.mealient.datasource.ServerUrlProvider
import gq.kirmanak.mealient.logging.Logger import gq.kirmanak.mealient.logging.Logger
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Response import okhttp3.Response
import java.io.IOException import java.io.IOException
@@ -37,6 +37,7 @@ class BaseUrlInterceptor @Inject constructor(
} }
private fun getBaseUrl() = runBlocking { 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()
} }
} }