Handle numeric web purchase cancellation error codes#1759
Draft
joshdholtz wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a defensive fix to ensure purchase cancellation is detected correctly when web/native layers forward a numeric cancellation error code (e.g., 1) instead of the expected string code (e.g., "1"), and introduces a regression test to cover that scenario.
Changes:
- Coerce
error.codeto a string before comparing againstPURCHASE_CANCELLED_ERRORwhen settingerror.userCancelled. - Add a Jest regression test validating
userCancelledis set when a numeric cancellation code is received.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/purchases.ts |
Updates cancellation detection logic across purchase methods to compare against a stringified error code. |
__tests__/index.test.js |
Adds a regression test for numeric cancellation code handling in purchasePackage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
616
to
619
| ).catch((error: PurchasesError) => { | ||
| error.userCancelled = | ||
| error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR; | ||
| String(error.code) === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR; | ||
| throw error; |
Comment on lines
+743
to
+747
| code: 1, | ||
| message: "", | ||
| readableErrorCode: "USER_CANCELLED", | ||
| underlyingErrorMessage: undefined, | ||
| userCancelled: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a defensive fix for web purchase cancellation handling in
react-native-purchases.Related issue: #1756
Changes
1Context
The underlying root cause is fixed in
purchases-js-hybrid-mappings, where web cancellation errors were being forwarded with numeric code1instead of string"1". This React Native change keeps cancellation handling correct even if a numeric code reaches this layer.Validation
__tests__/index.test.jscorepack yarn installfails on the repo's patchedtypescript@5.2.2dependency withCannot apply hunk #4