Loading...
Loading...
Use this skill when handling errors from the RevenueCat Android SDK. Covers PurchasesError, the PurchasesErrorCode enum, the userCancelled flag on PurchasesTransactionException, and the recommended UI response per code.
npx skill4agent add revenuecat/ai-toolkit rc-error-handlingBillingResponseCodePurchasesErrorpublic class PurchasesError(
val code: PurchasesErrorCode,
val underlyingErrorMessage: String? = null,
) {
val message: String // technical description, for logs
}PurchasesErrorCodeerror.messageawaitPurchase()PurchasesTransactionExceptionuserCancelled: Booleanawait*awaitOfferingsawaitGetProductsawaitCustomerInfoawaitRestorePurchasesExceptioncatchawait*PurchasesErrorCode| Code | Meaning | Handling |
|---|---|---|
| User backed out of the flow | Do nothing. |
| Product already active for the user | Refresh |
| Purchase entered pending state | Show a pending message. Wait for |
| Request failed due to connectivity | Prompt the user to retry. |
| Google Play issue | Prompt to retry or update Play Store. |
| Device or account cannot purchase | Show an explanatory message. |
| User not eligible for the offer | Show the base plan instead. |
| Call | Exception to catch | |
|---|---|---|
| | Yes |
| | No |
| | No |
| | No |
| | No |
userCancellederror.codetry {
val result = Purchases.sharedInstance.awaitPurchase(params)
handleSuccess(result.customerInfo)
} catch (e: PurchasesTransactionException) {
if (e.userCancelled) return
when (e.error.code) {
PurchasesErrorCode.PaymentPendingError -> showPendingMessage()
PurchasesErrorCode.ProductAlreadyPurchasedError -> {
val info = Purchases.sharedInstance.awaitCustomerInfo()
handleSuccess(info)
}
PurchasesErrorCode.NetworkError -> showRetryDialog()
else -> showGenericError(userFacingMessage(e.error))
}
}PurchasesExceptiontry {
val offerings = Purchases.sharedInstance.awaitOfferings()
displayOfferings(offerings)
} catch (e: PurchasesException) {
when (e.error.code) {
PurchasesErrorCode.NetworkError -> showOfflineFallback()
else -> logError(e.error)
}
}e.error.messagefun userFacingMessage(error: PurchasesError): String = when (error.code) {
PurchasesErrorCode.PurchaseCancelledError -> ""
PurchasesErrorCode.NetworkError ->
"Please check your internet connection and try again."
PurchasesErrorCode.StoreProblemError ->
"There was a problem with Google Play. Please try again."
PurchasesErrorCode.ProductAlreadyPurchasedError ->
"You already have this subscription."
PurchasesErrorCode.PaymentPendingError ->
"Your payment is being processed. We'll notify you when it completes."
else -> "Something went wrong. Please try again."
}PurchasesTransactionExceptionawaitPurchasePurchasesExceptionuserCancellederror.codePaymentPendingErrorProductAlreadyPurchasedErrorNetworkErrorerror.messageuserFacingMessage