Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit 21028454 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor: handle exceptions when fetching search results and suggestions in PlayStoreRepository

parent 893f5d2d
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -47,7 +47,9 @@ import foundation.e.apps.data.handleNetworkResult
import foundation.e.apps.data.login.AuthenticatorRepository
import foundation.e.apps.data.login.PlayStoreAuthenticator
import foundation.e.apps.data.playstore.utils.GPlayHttpClient
import foundation.e.apps.data.playstore.utils.GplayHttpRequestException
import foundation.e.apps.utils.SystemInfoProvider
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
@@ -100,12 +102,27 @@ class PlayStoreRepository @Inject constructor(
    )

    override suspend fun getSearchResults(pattern: String): List<Application> {
        val searchResult = playStoreSearchHelper.getSearchResults(pattern)
        val searchResult = try {
            playStoreSearchHelper.getSearchResults(pattern)
        } catch (e: CancellationException) {
            throw e
        } catch (e: GplayHttpRequestException) {
            Timber.w("Couldn't fetch search results.", e)
            emptyList()
        }

        return searchResult.map { it.toApplication(context) }
    }

    override suspend fun getSearchSuggestions(pattern: String): List<SearchSuggestion> {
        return playStoreSearchHelper.getSearchSuggestions(pattern)
        return try {
            playStoreSearchHelper.getSearchSuggestions(pattern)
        } catch (e: CancellationException) {
            throw e
        } catch (e: GplayHttpRequestException) {
            Timber.w("Couldn't fetch search suggestions.", e)
            emptyList()
        }
    }

    fun getAppsByCategory(category: String, pageUrl: String?): StreamCluster {