|
16 | 16 |
|
17 | 17 | package com.example.jetcaster.data
|
18 | 18 |
|
| 19 | +import android.util.Log |
19 | 20 | import com.example.jetcaster.data.room.TransactionRunner
|
20 | 21 | import kotlinx.coroutines.CoroutineDispatcher
|
21 | 22 | import kotlinx.coroutines.CoroutineScope
|
@@ -43,22 +44,26 @@ class PodcastsRepository(
|
43 | 44 | refreshingJob?.join()
|
44 | 45 | } else if (force || podcastStore.isEmpty()) {
|
45 | 46 | refreshingJob = scope.launch {
|
46 |
| - // Now fetch the podcasts, and add each to each store |
47 |
| - podcastsFetcher(SampleFeeds).collect { (podcast, episodes, categories) -> |
48 |
| - transactionRunner { |
49 |
| - podcastStore.addPodcast(podcast) |
50 |
| - episodeStore.addEpisodes(episodes) |
| 47 | + try { |
| 48 | + // Now fetch the podcasts, and add each to each store |
| 49 | + podcastsFetcher(SampleFeeds).collect { (podcast, episodes, categories) -> |
| 50 | + transactionRunner { |
| 51 | + podcastStore.addPodcast(podcast) |
| 52 | + episodeStore.addEpisodes(episodes) |
51 | 53 |
|
52 |
| - categories.forEach { category -> |
53 |
| - // First insert the category |
54 |
| - val categoryId = categoryStore.addCategory(category) |
55 |
| - // Now we can add the podcast to the category |
56 |
| - categoryStore.addPodcastToCategory( |
57 |
| - podcastUri = podcast.uri, |
58 |
| - categoryId = categoryId |
59 |
| - ) |
| 54 | + categories.forEach { category -> |
| 55 | + // First insert the category |
| 56 | + val categoryId = categoryStore.addCategory(category) |
| 57 | + // Now we can add the podcast to the category |
| 58 | + categoryStore.addPodcastToCategory( |
| 59 | + podcastUri = podcast.uri, |
| 60 | + categoryId = categoryId |
| 61 | + ) |
| 62 | + } |
60 | 63 | }
|
61 | 64 | }
|
| 65 | + } catch (e: Throwable) { |
| 66 | + Log.d("PodcastsRepository", "podcastsFetcher(SampleFeeds).collect error: $e") |
62 | 67 | }
|
63 | 68 | }
|
64 | 69 | }
|
|
0 commit comments