---
title: "在 React Native SDK 中处理错误"
description: "在 React Native SDK 中处理错误。"
---

SDK 返回的每个错误都是 `AdaptyErrorCode` 类型。以下是一个示例：

:::important
如果这些解决方案未能解决您的问题，请参阅[其他问题](#other-issues)，在联系支持团队之前执行相关步骤，以便我们更高效地为您提供帮助。
:::

```typescript showLineNumbers
try {
  const params: MakePurchaseParamsInput = {};
  await adapty.makePurchase(product, params);
} catch (error) {
  if (
    error instanceof AdaptyError &&
    error.adaptyCode === getErrorCode(ErrorCode['2'])
  ) {
    // payment cancelled
  }
}
```

## 系统 StoreKit 错误码 \{#system-storekit-codes\}

| 错误 | 错误码 | 解决方案 |
|-----|----|-----------|
| [unknown](https://developer.apple.com/documentation/storekit/skerror/code/unknown) | 0 | 表示发生了未知或意外错误的错误码。<br/> 请重试或参阅[其他问题](#other-issues)部分。 |
| [clientInvalid](https://developer.apple.com/documentation/storekit/skerror/code/clientinvalid) | 1 | 此错误码表示客户端不被允许执行所尝试的操作。 |
| [paymentCancelled](https://developer.apple.com/documentation/storekit/skerror/code/paymentcancelled) | 2 | <p>此错误码表示用户取消了付款请求。</p><p>无需采取任何操作，但从业务逻辑角度，您可以向用户提供折扣或稍后提醒他们。</p> |
| [paymentInvalid](https://developer.apple.com/documentation/storekit/skerror/code/paymentinvalid) | 3 | 此错误表示 App Store 无法识别某个付款参数。 |
| [paymentNotAllowed](https://developer.apple.com/documentation/storekit/skerror/code/paymentnotallowed) | 4 | 此错误码表示用户不被允许授权付款。 |
| [storeProductNotAvailable](https://developer.apple.com/documentation/storekit/skerror/code/storeproductnotavailable) | 5 | 此错误码表示所请求的产品在商店中不可用。<br/> 请尝试重新安装应用。 |
| [cloudServicePermissionDenied](https://developer.apple.com/documentation/storekit/skerror/code/cloudservicepermissiondenied) | 6 | 此错误码表示用户未允许访问云服务信息。 |
| [cloudServiceNetworkConnectionFailed](https://developer.apple.com/documentation/storekit/skerror/code/cloudservicenetworkconnectionfailed) | 7 | 此错误码表示设备无法连接到网络。 |
| [cloudServiceRevoked](https://developer.apple.com/documentation/storekit/skerror/code/cloudservicerevoked/) | 8 | 此错误码表示用户已撤销使用此云服务的权限。 |
| [privacyAcknowledgementRequired](https://developer.apple.com/documentation/storekit/skerror/code/privacyacknowledgementrequired) | 9 | 此错误码表示用户尚未确认 Apple 的隐私政策。 |
| [unauthorizedRequestData](https://developer.apple.com/documentation/storekit/skerror/code/unauthorizedrequestdata) | 10 | 此错误码表示应用正在尝试使用其没有所需权限的属性。 |
| [invalidOfferIdentifier](https://developer.apple.com/documentation/storekit/skerror/code/invalidofferidentifier) | 11 | <p>优惠 [`identifier`](https://developer.apple.com/documentation/storekit/skpaymentdiscount/identifier) 无效。例如，您未在 App Store 中设置具有该标识符的优惠，或您已撤销该优惠。</p><p>请确保您在 AppStore Connect 中设置了所需的优惠，并传入有效的优惠标识符。</p> |
| [invalidSignature](https://developer.apple.com/documentation/storekit/skerror/code/invalidsignature) | 12 | 此错误码表示付款折扣中的签名无效。 |
| [missingOfferParams](https://developer.apple.com/documentation/storekit/skerror/code/missingofferparams) | 13 | 此错误码表示付款折扣中缺少参数。 |
| [invalidOfferPrice](https://developer.apple.com/documentation/storekit/skerror/code/invalidofferprice/) | 14 | 此错误码表示您在 App Store Connect 中指定的价格不再有效。优惠必须始终代表折扣价格。 |

## 自定义 Android 错误码 \{#custom-android-codes\}

| 错误 | 错误码 | 解决方案 |
|-----|----|-----------|
| adaptyNotInitialized | 20 | 您需要通过 `Adapty.activate` 方法正确配置 Adapty SDK。了解如何[在 React Native 中](sdk-installation-reactnative)进行配置。 |
| productNotFound | 22 | 此错误表示请求购买的产品在商店中不可用。 |
| invalidJson | 23 | 付费墙 JSON 无效。请在 Adapty 看板中修复它。有关修复方法，请参阅[使用远程配置自定义付费墙](customize-paywall-with-remote-config)主题。 |
| currentSubscriptionToUpdateNotFoundInHistory | 24 | 未找到需要续订的原始订阅。 |
| pendingPurchase | 25 | 此错误表示购买状态为待处理而非已购买。有关详情，请参阅 Android 开发者文档中的[处理待处理交易](https://developer.android.com/google/play/billing/integrate#pending)页面。 |
| billingServiceTimeout | 97 | 此错误表示请求在 Google Play 响应之前已达到最大超时时间。例如，Play Billing 库调用所请求的操作执行延迟可能导致此问题。 |
| featureNotSupported | 98 | 当前设备上的 Play Store 不支持所请求的功能。 |
| billingServiceDisconnected | 99 | 此致命错误表示客户端应用通过 `BillingClient` 与 Google Play Store 服务的连接已断开。 |
| billingServiceUnavailable | 102 | 此临时错误表示 Google Play Billing 服务当前不可用。在大多数情况下，这意味着客户端设备与 Google Play Billing 服务之间的某处存在网络连接问题。 |
| billingUnavailable | 103 | <p>此错误表示在购买过程中发生了用户计费错误。可能发生此情况的示例包括：</p><p></p><p>1\. 用户设备上的 Play Store 应用已过期。</p><p>2. 用户位于不支持的国家/地区。</p><p>3. 用户是企业用户，其企业管理员已禁止用户进行购买。</p><p>4. Google Play 无法向用户的付款方式收费。例如，用户的信用卡可能已过期。</p><p>5. 用户未登录 Play Store 应用。</p> |
| developerError | 105 | 这是一个致命错误，表示您不正确地使用了 API。 |
| billingError | 106 | 这是一个致命错误，表示 Google Play 本身存在内部问题。 |
| itemAlreadyOwned | 107 | 消耗型商品已被购买。 |
| itemNotOwned | 108 | 此错误表示对该商品请求的操作失败。 |

## 自定义 StoreKit 错误码 \{#custom-storekit-codes\}

| 错误 | 错误码 | 解决方案 |
|-----|----|-----------|
| noProductIDsFound | 1000 | <p>此错误表示您在付费墙上请求的产品在 App Store 中均不可购买，尽管它们已在 App Store 中列出。此错误有时可能伴随 `InvalidProductIdentifiers` 警告。如果警告出现时没有错误，可安全忽略。</p><p>如果遇到此错误，请按照[修复 Code-1000 `noProductIDsFound` 错误](InvalidProductIdentifiers-react-native)部分中的步骤操作。</p> |
| productRequestFailed | 1002 | <p>目前无法获取可用产品。可能原因：</p><p></p><p>- 尚未创建缓存，同时又没有网络连接。</p> |
| cantMakePayments | 1003 | 此设备不允许应用内购买。请参阅故障排除[指南](cantMakePayments-react-native)。 |
| noPurchasesToRestore | 1004 | 此错误表示 Google Play 未找到可恢复的购买记录。 |
| cantReadReceipt | 1005 | <p>设备上没有有效的收据。这在沙盒测试期间可能是一个问题。</p><p>无需采取任何操作，但从业务逻辑角度，您可以向用户提供折扣或稍后提醒他们。</p> |
| productPurchaseFailed | 1006 | 产品购买失败。 |
| refreshReceiptFailed | 1010 | 此错误表示未收到收据。仅适用于 StoreKit 1。 |
| receiveRestoredTransactionsFailed | 1011 | 购买恢复失败。 |

## 自定义网络错误码 \{#custom-network-codes\}

| 错误 | 错误码 | 解决方案 |
| :------------------- | :--- |:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| notActivated | 2002 | Adapty SDK 未激活。您需要使用 `Adapty.activate` 方法正确[配置 Adapty SDK](sdk-installation-reactnative)。 |
| badRequest | 2003 | 错误请求。<br/> 请确保您已完成[与 App Store 集成](app-store-connection-configuration)所需的所有步骤。 |
| serverError | 2004 | 服务器错误。<br/> 请稍后重试。如果问题未解决，请联系 Adapty 支持团队。 |
| networkFailed | 2005 | 此错误表示用户设备的网络连接存在问题。<br/> 请尝试禁用 VPN，或从移动网络切换到 WiFi，或反之。 |
| decodingFailed | 2006 | 此错误表示响应解码失败。<br/> 请检查您的代码，确保您发送的参数有效。例如，此错误可能表示您使用了无效的 API 密钥。 |
| encodingFailed | 2009 | 此错误表示请求编码失败。 |
| missingURL | 2010 | 请求的 URL 为 nil。 |
| analyticsDisabled | 3000 | 由于您已[选择退出](analytics-integration#disabling-external-analytics-for-a-specific-customer)，我们无法处理分析事件。 |
| wrongParam | 3001 | 此错误表示您的某些参数不正确。<br/> 如果您正在使用 Adapty 付费墙编辑工具且因此错误无法显示付费墙，请在付费墙编辑工具中开启 **Show on device**。<br/> 此问题的另一个可能原因是本地[备用付费墙](fallback-paywalls)文件版本与 SDK 版本不匹配。请在看板中下载新文件。 |
| activateOnceError | 3005 | 不可多次调用 `.activate` 方法。 |
| profileWasChanged | 3006 | 操作期间用户画像已更改。<br/> 当您调用 `identify` 后，在 `identify` 成功之前又调用了其他方法时，可能会发生此错误。为避免此问题，请等待 `identify` 成功后再调用其他方法。 |
| unsupportedData | 3007 | 此错误表示 SDK 不支持该数据格式。 |
| persistingDataError | 3100 | 保存数据时发生错误。 |
| fetchTimeoutError | 3101 | 此错误表示获取操作已超时。 |

## 其他问题 \{#other-issues\}

如果您尚未找到解决方案，可以采取以下步骤：

- **将 SDK 升级到最新版本**：我们始终建议升级到最新的 SDK 版本，因为它们更稳定并包含已知问题的修复。
- **联系支持团队或在[支持论坛](https://adapty.featurebase.app/)中获取开发者社区的帮助**。
- **通过 [support@adapty.io](mailto:support@adapty.io) 或在线聊天联系支持团队**：如果您还没准备好升级 SDK，或升级后问题仍未解决，请联系我们的支持团队。请注意，如果您[启用详细日志记录](sdk-installation-reactnative)并与团队共享日志，您的问题将得到更快解决。您也可以附上相关代码片段。