iOS - Handle errors
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 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 the original error around which the wrapper was initially built.
adaptyErrorCode 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.
do {
let info = try await Adapty.makePurchase(product: product)
} catch {
if error.adaptyErrorCode == .paymentCancelled {
// purchase was cancelled
// you can offer discount to your user or remind them later
}
}
StoreKit errors
Error | Code | Description |
---|---|---|
unknown | 0 | Error code indicating that an unknown or unexpected error occurred. |
clientInvalid | 1 | This error code indicates that the client is not allowed to perform the attempted action. |
paymentCancelled | 2 | This error code indicates that the user canceled a payment request. No action is required, but in terms of the business logic, you can offer a discount to your user or remind them later. |
paymentInvalid | 3 | This error indicates that one of the payment parameters was not recognized by the App Store. |
paymentNotAllowed | 4 | This error code indicates that the user is not allowed to authorize payments. |
storeProductNotAvailable | 5 | This error code indicates that the requested product is not available in the store. |
cloudServicePermissionDenied | 6 | This error code indicates that the user has not allowed access to Cloud service information. |
cloudServiceNetworkConnectionFailed | 7 | This error code indicates that the device could not connect to the network. |
cloudServiceRevoked | 8 | This error code indicates that the user has revoked permission to use this cloud service. |
privacyAcknowledgementRequired | 9 | This error code indicates that the user has not yet acknowledged Apple’s privacy policy. |
unauthorizedRequestData | 10 | This error code indicates that the app is attempting to use a property for which it does not have the required entitlement. |
invalidOfferIdentifier | 11 | The offer Make sure you set up desired offers in AppStore Connect and pass a valid offer identifier. |
invalidSignature | 12 | This error code indicates that the signature in a payment discount is not valid. |
missingOfferParams | 13 | This error code indicates that parameters are missing in a payment discount. |
invalidOfferPrice | 14 | This error code indicates that the price you specified in App Store Connect is no longer valid. Offers must always represent a discounted price. |
noProductIDsFound | 1000 | This error indicates that none of the products you requested on the paywall are available for purchase in the App Store, even though they’re listed there. This error may sometimes come with an If you’re encountering this error, follow the steps in the Fix for Code-1000 |
noProductsFound | 1001 | This error indicates that the product requested for purchase is not available in the store. |
productRequestFailed | 1002 | Unable to fetch available products at the moment. |
cantMakePayments | 1003 | In-app purchases are not allowed on this device. |
noPurchasesToRestore | 1004 | This error indicates that Google Play did not find the purchase to restore. |
cantReadReceipt | 1005 | There is no valid receipt available on the device. This can be an issue during sandbox testing. In the sandbox, you won't have a valid receipt file until you actually make a purchase, so make sure you do one before accessing it. During sandbox testing also make sure you signed in on a device with a valid Apple sandbox account. |
productPurchaseFailed | 1006 | Product purchase failed. |
missingOfferSigningParams | 1007 | This error indicates issues with Adapty integration or with offers. Refer to the Configure App Store integration and to Offers for details on how to set them up. |
Network errors
Error | Code | Description |
---|---|---|
notActivated | 2002 | You need to properly configure Adapty SDK by Adapty.activate method. |
badRequest | 2003 | Bad request. |
serverError | 2004 | Server error. |
networkFailed | 2005 | The error indicates issues with the network connection. |
decodingFailed | 2006 | This error indicates that response decoding failed. |
encodingFailed | 2009 | This error indicates that request encoding failed. |
missingURL | 2010 | The requested URL is nil. |
General errors
Error | Code | Description |
---|---|---|
analyticsDisabled | 3000 | We can't handle analytics events, since you've opted it out. |
wrongParam | 3001 | This error indicates that some of your parameters are not correct do match the constraints. |
activateOnceError | 3005 | It is not possible to call .activate method more than once. |
profileWasChanged | 3006 | The user profile was changed during the operation. |
persistingDataError | 3100 | It was an error while saving data. |
operationInterrupted | 9000 | This operation was interrupted by the system. |
Warnings
Warnings don’t need to be fixed unless they lead to errors.
| operationInterrupted | 9000 | This operation was interrupted by the system. |