diff --git a/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModel.kt b/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModel.kt index fb17ce9127..0df75b8895 100644 --- a/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModel.kt +++ b/ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModel.kt @@ -227,7 +227,9 @@ internal class PaywallViewModelImpl( } if (currentOffering == null) { - _state.value = PaywallState.Error("No offering or current offering") + _state.value = PaywallState.Error( + "The RevenueCat dashboard does not have a current offering configured.", + ) } else { _state.value = calculateState( currentOffering, @@ -236,7 +238,9 @@ internal class PaywallViewModelImpl( ) } } catch (e: PurchasesException) { - _state.value = PaywallState.Error(e.toString()) + _state.value = PaywallState.Error( + "Error ${e.code.code}: ${e.code.description}", + ) } } } diff --git a/ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModelTest.kt b/ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModelTest.kt index 7889f0acae..21799ecab2 100644 --- a/ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModelTest.kt +++ b/ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModelTest.kt @@ -182,6 +182,51 @@ class PaywallViewModelTest { .isTrue } + @Test + fun `Error loading offerings`() { + coEvery { purchases.awaitOfferings() } throws PurchasesException( + PurchasesError(PurchasesErrorCode.NetworkError + )) + + val model = create( + activeSubscriptions = setOf(TestData.Packages.monthly.product.id), + nonSubscriptionTransactionProductIdentifiers = setOf(TestData.Packages.lifetime.product.id) + ) + + coVerify { purchases.awaitOfferings() } + + val state = model.state.value + if (state !is PaywallState.Error) { + fail("Invalid state") + return + } + + assertThat(state.errorMessage).isEqualTo("Error 10: Error performing request.") + } + + @Test + fun `Error loading empty offerings`() { + coEvery { purchases.awaitOfferings() } returns Offerings( + null, + mapOf() + ) + + val model = create( + activeSubscriptions = setOf(TestData.Packages.monthly.product.id), + nonSubscriptionTransactionProductIdentifiers = setOf(TestData.Packages.lifetime.product.id) + ) + + coVerify { purchases.awaitOfferings() } + + val state = model.state.value + if (state !is PaywallState.Error) { + fail("Invalid state") + return + } + + assertThat(state.errorMessage).isEqualTo("The RevenueCat dashboard does not have a current offering configured.") + } + @Test fun `Should load selected offering`() { val offering = TestData.template1Offering