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

Commit 7b15d902 authored by dev-12's avatar dev-12
Browse files

Merge branch '3847-handle-404-apps' into 'main'

correctly throw app not found error

See merge request !636
parents ea2db314 f0205501
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

package foundation.e.apps.data

import com.aurora.gplayapi.exceptions.InternalException
import foundation.e.apps.data.login.exceptions.GPlayException
import foundation.e.apps.data.playstore.utils.GPlayHttpClient
import foundation.e.apps.data.playstore.utils.GplayHttpRequestException
@@ -40,6 +41,10 @@ private const val INITIAL_DELAY_RETRY_IN_SECONDS = 1
suspend fun <T> handleNetworkResult(call: suspend () -> T): ResultSupreme<T> {
    return try {
        ResultSupreme.Success(call())
    } catch (exception: InternalException.AppNotFound) {
        // catch and rethrow the error because we catch all `Exception` in the last catch block
        // if this error is swallowed caller will not get the app not found error
        throw exception
    } catch (e: CancellationException) {
        throw e
    } catch (e: SocketTimeoutException) {
+10 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.aurora.gplayapi.data.models.Category
import com.aurora.gplayapi.data.models.ContentRating
import com.aurora.gplayapi.data.models.PlayFile
import com.aurora.gplayapi.data.models.StreamCluster
import com.aurora.gplayapi.exceptions.InternalException
import com.aurora.gplayapi.helpers.AppDetailsHelper
import com.aurora.gplayapi.helpers.ContentRatingHelper
import com.aurora.gplayapi.helpers.PurchaseHelper
@@ -52,6 +53,7 @@ import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.net.HttpURLConnection
import javax.inject.Inject
import com.aurora.gplayapi.data.models.App as GplayApp

@@ -179,7 +181,14 @@ class PlayStoreRepository @Inject constructor(

    override suspend fun getAppDetails(packageName: String): Application =
        withContext(Dispatchers.IO) {
            var appDetails: GplayApp = getAppDetailsHelper().getAppByPackageName(packageName)
            var appDetails: GplayApp = try {
                getAppDetailsHelper().getAppByPackageName(packageName)
            } catch (exception: GplayHttpRequestException) {
                if (exception.status == HttpURLConnection.HTTP_NOT_FOUND) {
                    throw InternalException.AppNotFound()
                }
                throw exception
            }

            if (!isEmulator() && appDetails.versionCode == 0L && isAnonymousUser()) {
                // Google Play returns limited result ( i.e. version code being 0) with a stale token,