Skip to content

Handle numeric web purchase cancellation error codes#1759

Draft
joshdholtz wants to merge 1 commit into
mainfrom
codex/guard-web-cancel-error-codes
Draft

Handle numeric web purchase cancellation error codes#1759
joshdholtz wants to merge 1 commit into
mainfrom
codex/guard-web-cancel-error-codes

Conversation

@joshdholtz
Copy link
Copy Markdown
Member

@joshdholtz joshdholtz commented May 6, 2026

Summary

Adds a defensive fix for web purchase cancellation handling in react-native-purchases.

Related issue: #1756

Changes

  • coerce incoming purchase error codes to string before checking for cancellation
  • add a regression test covering numeric cancellation code 1

Context

The underlying root cause is fixed in purchases-js-hybrid-mappings, where web cancellation errors were being forwarded with numeric code 1 instead of string "1". This React Native change keeps cancellation handling correct even if a numeric code reaches this layer.

Validation

  • Added regression test in __tests__/index.test.js
  • Local JS build/test execution is currently blocked in this workspace because corepack yarn install fails on the repo's patched typescript@5.2.2 dependency with Cannot apply hunk #4

@joshdholtz joshdholtz added the pr:fix A bug fix label May 6, 2026
@joshdholtz joshdholtz changed the title [codex] Guard numeric web cancellation error codes Handle numeric web purchase cancellation error codes May 6, 2026
@joshdholtz joshdholtz marked this pull request as ready for review May 6, 2026 00:36
Copilot AI review requested due to automatic review settings May 6, 2026 00:36
@joshdholtz joshdholtz requested a review from a team as a code owner May 6, 2026 00:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.code to a string before comparing against PURCHASE_CANCELLED_ERROR when setting error.userCancelled.
  • Add a Jest regression test validating userCancelled is 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 thread src/purchases.ts
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 thread __tests__/index.test.js
Comment on lines +743 to +747
code: 1,
message: "",
readableErrorCode: "USER_CANCELLED",
underlyingErrorMessage: undefined,
userCancelled: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants