mirror of
https://github.com/jellyfin/jellyfin-android.git
synced 2026-09-03 05:10:27 +03:00
Merge pull request #33 from andresesfm/patch-1
Fixes crash when entering incorrect Url
This commit is contained in:
@@ -12,6 +12,7 @@ import org.jellyfin.mobile.utils.Constants.SERVER_INFO_PATH
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
|
||||
suspend fun WebappActivity.checkServerUrlAndConnection(enteredUrl: String): HttpUrl? {
|
||||
val normalizedUrl = enteredUrl.run {
|
||||
@@ -69,6 +70,11 @@ suspend fun fetchServerInfo(httpClient: OkHttpClient, url: HttpUrl): String? {
|
||||
val serverInfoUrl = url.resolve(SERVER_INFO_PATH) ?: return null
|
||||
val request = httpClient.newCall(Request.Builder().url(serverInfoUrl).build())
|
||||
return withContext(Dispatchers.IO) {
|
||||
request.execute().use { it.body?.string() }
|
||||
try {
|
||||
request.execute().use { it.body?.string() }
|
||||
} catch (e: IOException) {
|
||||
Timber.e(e, "Cannot connect to server")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user