Merge pull request #3113 from Bnyro/master

Better error messages when a video is unavailable
This commit is contained in:
Bnyro 2023-02-18 10:32:18 +01:00 committed by GitHub
commit c31f17ab11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -3,4 +3,7 @@ package com.github.libretube.api.obj
import kotlinx.serialization.Serializable
@Serializable
data class Message(val message: String? = null)
data class Message(
val error: String? = null,
val message: String? = null
)

View File

@ -44,10 +44,12 @@ import com.github.libretube.api.CronetHelper
import com.github.libretube.api.JsonHelper
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.ChapterSegment
import com.github.libretube.api.obj.Message
import com.github.libretube.api.obj.PipedStream
import com.github.libretube.api.obj.Segment
import com.github.libretube.api.obj.StreamItem
import com.github.libretube.api.obj.Streams
import com.github.libretube.api.obj.Token
import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.databinding.FragmentPlayerBinding
@ -117,6 +119,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.datetime.LocalDate
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import retrofit2.HttpException
@ -652,13 +655,13 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
streams = try {
RetrofitInstance.api.getStreams(videoId!!)
} catch (e: IOException) {
println(e)
Log.e(TAG(), "IOException, you might not have internet connection")
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show()
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_LONG).show()
return@launchWhenCreated
} catch (e: HttpException) {
Log.e(TAG(), "HttpException, unexpected response")
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show()
val errorMessage = e.response()?.errorBody()?.string()?.let {
JsonHelper.json.decodeFromString<Message>(it).message
} ?: context?.getString(R.string.server_error) ?: ""
Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show()
return@launchWhenCreated
}