Skip to content

Commit 3e76904

Browse files
committed
Avoid crashing if Holodex response is unparsable
1 parent 95d0abc commit 3e76904

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/src/main/kotlin/com/livetl/android/data/feed/FeedService.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import kotlinx.coroutines.Dispatchers
1313
import kotlinx.coroutines.SupervisorJob
1414
import kotlinx.coroutines.withContext
1515
import kotlinx.serialization.json.Json
16+
import timber.log.Timber
1617
import javax.inject.Inject
1718

1819
class FeedService @Inject constructor(
@@ -23,7 +24,7 @@ class FeedService @Inject constructor(
2324
suspend fun getFeed(
2425
organization: String? = "Hololive",
2526
status: StreamStatus,
26-
): List<Stream> = withContext(Dispatchers.IO) {
27+
): List<Stream> = withContext(SupervisorJob() + Dispatchers.IO) {
2728
val result = client.get<HttpResponse> {
2829
url {
2930
baseUrl()
@@ -43,8 +44,13 @@ class FeedService @Inject constructor(
4344
baseHeaders()
4445
}
4546

46-
val response: HolodexVideosResponse = json.decodeFromString(result.readText())
47-
response.items
47+
try {
48+
val response: HolodexVideosResponse = json.decodeFromString(result.readText())
49+
response.items
50+
} catch (e: Exception) {
51+
Timber.e(e)
52+
emptyList()
53+
}
4854
}
4955

5056
suspend fun getVideoInfo(videoId: String): Stream = withContext(SupervisorJob() + Dispatchers.IO) {

0 commit comments

Comments
 (0)