Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the way to handle the error if purchase(sk2Product) fails due to an error when posting the receipt #1177

Conversation

Juanpe
Copy link
Contributor

@Juanpe Juanpe commented Jan 14, 2022

Checklist

  • If applicable, unit tests
  • If applicable, create follow-up issues for purchases-android and hybrids

Motivation

Resolves #1114

Now, if purchase(sk2Product:) fails because of an error when posting the receipt, the method returns ErrorCode.unknownError because it assumes it always receives a StoreKitError. The goal of this PR is to improve the way to handle the error.

Description

  • Add a where condition to know if the error type is StoreKitError, if not the method returns the error received.
  • Add a new test method to validate this logic.

@@ -215,7 +243,7 @@ class PurchasesOrchestratorTests: StoreKitConfigTestCase {
expect(self.backend.invokedPostReceiptDataParameters?.isRestore).to(beFalse())
}

func testStoreKit2TransactionListenerDelegateWithObesrverMode() async throws {
func testStoreKit2TransactionListenerDelegateWithObserverMode() async throws {
Copy link
Contributor Author

@Juanpe Juanpe Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix a typo 🙂

expect(userCancelled) == false
expect(customerInfo).to(beNil())
expect(error).toNot(beNil())
expect(error?.localizedDescription).to(equal(expectedError.localizedDescription))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check the domain and code too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense.

Finally, I used the matchError, a predicate provided by Nimble to compare errors. Both the code and the domain are internally validated 👍🏼

Copy link
Contributor

@NachoSoto NachoSoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Copy link
Member

@aboedo aboedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for taking care of this @Juanpe! 🔥

@aboedo aboedo merged commit f0bfea1 into RevenueCat:main Jan 17, 2022
@Juanpe Juanpe deleted the purchase_package_check_if_thrown_error_is_StoreKitError branch January 17, 2022 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PurchasesOrchestrator.purchase(package:completion:) assumes that purchase(sk2Product:) throws StoreKitError
3 participants