Show a better error in InterUriScreen

This commit is contained in:
vfsfitvnm 2022-06-19 11:28:44 +02:00
parent 6c15889360
commit a3332d8f06
2 changed files with 8 additions and 4 deletions

View file

@ -87,7 +87,7 @@ fun IntentUriScreen(uri: Uri) {
} }
} ?: uri.getQueryParameter("v")?.let { videoId -> } ?: uri.getQueryParameter("v")?.let { videoId ->
YouTube.song(videoId).toNullable()?.map { listOf(it) } YouTube.song(videoId).toNullable()?.map { listOf(it) }
} ?: Outcome.Error.Network } ?: Outcome.Error.Unhandled(Error("Missing URL parameters"))
} }
} }

View file

@ -57,9 +57,13 @@ fun <T> Outcome<T>?.toNotNull(): Outcome<T?> {
} }
} }
fun <T> Outcome<T?>.toNullable(): Outcome<T>? { fun <T> Outcome<T?>.toNullable(error: Outcome.Error? = null): Outcome<T>? {
return valueOrNull?.let { return when (this) {
Outcome.Success(it) is Outcome.Success -> value?.let { Outcome.Success(it) } ?: error
is Outcome.Recovered -> value?.let { Outcome.Success(it) } ?: error
is Outcome.Initial -> this
is Outcome.Loading -> this
is Outcome.Error -> this
} }
} }