Error Handling (SKError, NSError, Error)

In this topic we describe how you can handle most of the SKError's errors e.g.: SKErrorPaymentCancelled, SKErrorInvalidOfferIdentifier, SKErrorUnknown, etc.

Adapty SDK has its own wrapper for all kinds of errors, called AdaptyError. Basically, every error returned by an SDK is AdaptyError. It has two useful properties: originalError and adaptyErrorCode, described below.

originalError

It contains an original error in case you need the original one to work with. Can be SKError, NSError or just general Swift Error. This property is optional since some errors can be generated directly by SDK, like inconsistent or missing data, and won't have original error around which wrapper was initially built.

adaptyErrorCode

This one can be used to handle common issues, like:

  • invalid credentials
  • network errors
  • cancelled payments
  • billing issues
  • invalid receipt
  • and much more

It's pretty easy to check the error for specific codes and react to them accordingly.

import Adapty

Adapty.makePurchase(product: product) { (purchaserInfo, receipt, appleValidationResult, _, error) in
    if error?.adaptyErrorCode == .paymentCancelled {
        // purchase was cancelled
        // you can offer discount to your user or remind them later
    }
}

Most common errors and how to handle them

StoreKit errors

AdaptyErrorеCode.paymentCancelled

Corresponds to SKError.Code.paymentCancelled.

Issue:
User cancelled their purchase and was not charged.

Workaround:
No action required, but in terms of the business logic, you can offer a discount to your user or remind them later.

AdaptyErrorCode.cantReadReceipt

Issue:
There is no valid receipt available on the device. Can be an issue during sandbox testing.

Workaround:
In the sandbox, you won't have a valid receipt file until you actually make a purchase, so make sure you did one before accessing it. During sandbox testing also make sure you signed in on a device with a valid Apple sandbox account.

AdaptyErrorCode.invalidOfferIdentifier

Corresponds to SKError.Code.invalidOfferIdentifier.

Issue:
The offer identifier is not valid. For example, you have not set up an offer with that identifier in the App Store, or you have revoked the offer.

Workaround:
Make sure you set up desired offers in AppStore connect and pass a valid offer identifier.

AdaptyErrorCode.noProductsFound

Issue:
We were unable to fetch any products from StoreKit.

Workaround:
Make sure:
– you created products in AppStore connect;
– you added products in Adapty dashboard;
– you running the simulator under iOS 14 or if you want to continue using iOS 14 make sure you run it on a real device.

AdaptyErrorCode.missingOfferSigningParams

Issue:
A signature generated for purchase with a promotional offer was missing or invalid.

Workaround:
Make sure you've uploaded Subscription Key in Adapty Dashboard for using promotional offers.

General error list

StoreKit errors

ErrorCodeDescription
unknown0Error code indicating that an unknown or unexpected error occurred.
clientInvalid1Error code indicating that the client is not allowed to perform the attempted action.
paymentCancelled2Error code indicating that the user canceled a payment request.
paymentInvalid3Error code indicating that one of the payment parameters was not recognized by the App Store.
paymentNotAllowed4Error code indicating that the user is not allowed to authorize payments.
storeProductNotAvailable5Error code indicating that the requested product is not available in the store.
cloudServicePermissionDenied6Error code indicating that the user has not allowed access to Cloud service information.
cloudServiceNetworkConnectionFailed7Error code indicating that the device could not connect to the network.
cloudServiceRevoked8Error code indicating that the user has revoked permission to use this cloud service.
privacyAcknowledgementRequired9Error code indicating that the user has not yet acknowledged Apple’s privacy policy for Apple Music.
unauthorizedRequestData10Error code indicating that the app is attempting to use a property for which it does not have the required entitlement.
invalidOfferIdentifier11Error code indicating that the offer identifier is invalid.
invalidSignature12Error code indicating that the signature in a payment discount is not valid.
missingOfferParams13Error code indicating that parameters are missing in a payment discount.
invalidOfferPrice14Error code indicating that the price you specified in App Store Connect is no longer valid.
noProductIDsFound1000No In-App Purchase product identifiers were found.
noProductsFound1001No In-App Purchases were found.
productRequestFailed1002Unable to fetch available In-App Purchase products at the moment.
cantMakePayments1003In-App Purchases are not allowed on this device.
noPurchasesToRestore1004No purchases to restore.
cantReadReceipt1005Can't find a valid receipt.
productPurchaseFailed1006Product purchase failed.
missingOfferSigningParams1007Missing offer signing required params.
fallbackPaywallsNotRequired1008Fallback paywalls are not required.

Network errors

ErrorCodeDescription
emptyResponse2000Response is empty.
emptyData2001Request data is empty.
authenticationError2002You need to be authenticated to perform requests.
badRequest2003Bad request.
serverError2004Server error.
failed2005Network request failed.
unableToDecode2006We could not decode the response.
missingParam2007Missing some of the required params.
invalidProperty2008Received invalid property data.
encodingFailed2009Parameters encoding failed.
missingURL2010Request url is nil.

General errors

ErrorCodeDescription
analyticsDisabled3000We can't handle analytics events, since you've opted it out.

Did this page help you?