app_store_server_library/primitives/
error_payload.rs

1use serde::{Deserialize, Deserializer, Serialize};
2use serde_repr::{Deserialize_repr, Serialize_repr};
3
4/// Enum representing different API errors with associated status codes.
5#[derive(Debug, Clone, Deserialize_repr, Serialize_repr, PartialEq, Hash)]
6#[repr(i64)]
7pub enum APIError {
8    /// An error that indicates an invalid request.
9    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/generalbadrequesterror)
10    GeneralBadRequest = 4000000,
11
12    /// An error that indicates an invalid app identifier.
13    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidappidentifiererror)
14    InvalidAppIdentifier = 4000002,
15
16    /// An error that indicates an invalid request revision.
17    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidrequestrevisionerror)
18    InvalidRequestRevision = 4000005,
19
20    /// An error that indicates an invalid transaction identifier.
21    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidtransactioniderror)
22    InvalidTransactionId = 4000006,
23
24    /// An error that indicates an invalid original transaction identifier.
25    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidoriginaltransactioniderror)
26    InvalidOriginalTransactionId = 4000008,
27
28    /// An error that indicates an invalid extend-by-days value.
29    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidextendbydayserror)
30    InvalidExtendByDays = 4000009,
31
32    /// An error that indicates an invalid reason code.
33    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidextendreasoncodeerror)
34    InvalidExtendReasonCode = 4000010,
35
36    /// An error that indicates an invalid request identifier.
37    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidrequestidentifiererror)
38    InvalidRequestIdentifier = 4000011,
39
40    /// An error that indicates that the start date is earlier than the earliest allowed date.
41    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/startdatetoofarinpasterror)
42    StartDateTooFarInPast = 4000012,
43
44    /// An error that indicates that the end date precedes the start date, or the two dates are equal.
45    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/startdateafterenddateerror)
46    StartDateAfterEndDate = 4000013,
47
48    /// An error that indicates the pagination token is invalid.
49    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidpaginationtokenerror)
50    InvalidPaginationToken = 4000014,
51
52    /// An error that indicates the start date is invalid.
53    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidstartdateerror)
54    InvalidStartDate = 4000015,
55
56    /// An error that indicates the end date is invalid.
57    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidenddateerror)
58    InvalidEndDate = 4000016,
59
60    /// An error that indicates the pagination token expired.
61    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/paginationtokenexpirederror)
62    PaginationTokenExpired = 4000017,
63
64    /// An error that indicates the notification type or subtype is invalid.
65    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidnotificationtypeerror)
66    InvalidNotificationType = 4000018,
67
68    /// An error that indicates the request is invalid because it has too many constraints applied.
69    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/multiplefilterssuppliederror)
70    MultipleFiltersSupplied = 4000019,
71
72    /// An error that indicates the test notification token is invalid.
73    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidtestnotificationtokenerror)
74    InvalidTestNotificationToken = 4000020,
75
76    /// An error that indicates an invalid sort parameter.
77    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidsorterror)
78    InvalidSort = 4000021,
79
80    /// An error that indicates an invalid product type parameter.
81    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidproducttypeerror)
82    InvalidProductType = 4000022,
83
84    /// An error that indicates the product ID parameter is invalid.
85    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidproductiderror)
86    InvalidProductId = 4000023,
87
88    /// An error that indicates an invalid subscription group identifier.
89    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidsubscriptiongroupidentifiererror)
90    InvalidSubscriptionGroupIdentifier = 4000024,
91
92    /// An error that indicates the query parameter exclude-revoked is invalid.
93    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidexcluderevokederror)
94    InvalidExcludeRevoked = 4000025,
95
96    /// An error that indicates an invalid in-app ownership type parameter.
97    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidinappownershiptypeerror)
98    InvalidInAppOwnershipType = 4000026,
99
100    /// An error that indicates a required storefront country code is empty.
101    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidemptystorefrontcountrycodelisterror)
102    InvalidEmptyStorefrontCountryCodeList = 4000027,
103
104    /// An error that indicates a storefront code is invalid.
105    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidstorefrontcountrycodeerror)
106    InvalidStorefrontCountryCode = 4000028,
107
108    /// An error that indicates the revoked parameter contains an invalid value.
109    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidrevokederror)
110    InvalidRevoked = 4000030,
111
112    /// An error that indicates the status parameter is invalid.
113    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidstatuserror)
114    InvalidStatus = 4000031,
115
116    /// An error that indicates the value of the account tenure field is invalid.
117    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidaccounttenureerror)
118    InvalidAccountTenure = 4000032,
119
120    /// An error that indicates the value of the app account token is invalid.
121    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidappaccounttokenerror)
122    InvalidAppAccountToken = 4000033,
123
124    /// An error that indicates the consumption status is invalid.
125    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidconsumptionstatuserror)
126    InvalidConsumptionStatus = 4000034,
127
128    /// An error that indicates the customer consented status is invalid.
129    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidcustomerconsentederror)
130    InvalidCustomerConsented = 4000035,
131
132    /// An error that indicates the delivery status is invalid.
133    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invaliddeliverystatuserror)
134    InvalidDeliveryStatus = 4000036,
135
136    /// An error that indicates the lifetime dollars purchased field is invalid.
137    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidlifetimedollarspurchasederror)
138    InvalidLifetimeDollarsPurchased = 4000037,
139
140    /// An error that indicates the lifetime dollars refunded field is invalid.
141    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidlifetimedollarsrefundederror)
142    InvalidLifetimeDollarsRefunded = 4000038,
143
144    /// An error that indicates the platform parameter is invalid.
145    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidplatformerror)
146    InvalidPlatform = 4000039,
147
148    /// An error that indicates the play time parameter is invalid.
149    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidplaytimeerror)
150    InvalidPlayTime = 4000040,
151
152    /// An error that indicates the sample content provided parameter is invalid.
153    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invalidsamplecontentprovidederror)
154    InvalidSampleContentProvided = 4000041,
155
156    /// An error that indicates the user status parameter is invalid.
157    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/invaliduserstatuserror)
158    InvalidUserStatus = 4000042,
159
160    /// An error that indicates the transaction is not consumable.
161    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/transactionnotconsumableerror)
162    #[deprecated(since="2.1.0")]
163    InvalidTransactionNotConsumable = 4000043,
164
165    /// An error that indicates the transaction identifier represents an unsupported in-app purchase type.
166    ///
167    /// [InvalidTransactionTypeNotSupportedError](https://developer.apple.com/documentation/appstoreserverapi/invalidtransactiontypenotsupportederror)
168    InvalidTransactionTypeNotSupported = 4000047,
169
170    /// An error that indicates the endpoint doesn't support an app transaction ID.
171    ///
172    /// [AppTransactionIdNotSupportedError](https://developer.apple.com/documentation/appstoreserverapi/apptransactionidnotsupportederror)
173    AppTransactionIdNotSupportedError = 4000048,
174
175    /// An error that indicates the app account token value is not a valid UUID.
176    ///
177    /// [InvalidAppAccountTokenUUID](https://developer.apple.com/documentation/appstoreserverapi/invalidappaccounttokenuuiderror)
178    InvalidAppAccountTokenUUID = 4000183,
179
180    /// An error that indicates the transaction is for a product the customer obtains through Family Sharing, which the endpoint doesn't support.
181    ///
182    /// [FamilyTransactionNotSupported](https://developer.apple.com/documentation/appstoreserverapi/familytransactionnotsupportederror)
183    FamilyTransactionNotSupported = 4000185,
184
185    /// An error that indicates the endpoint expects an original transaction identifier.
186    ///
187    /// [TransactionIdNotOriginalTransactionId](https://developer.apple.com/documentation/appstoreserverapi/transactionidnotoriginaltransactioniderror)
188    TransactionIdNotOriginalTransactionId = 4000187,
189
190    /// An error that indicates the subscription doesn't qualify for a renewal-date extension due to its subscription state.
191    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/subscriptionextensionineligibleerror)
192    SubscriptionExtensionIneligible = 4030004,
193
194    /// An error that indicates the subscription doesn’t qualify for a renewal-date extension because it has already received the maximum extensions.
195    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/subscriptionmaxextensionerror)
196    SubscriptionMaxExtension = 4030005,
197
198    /// An error that indicates a subscription isn't directly eligible for a renewal date extension because the user obtained it through Family Sharing.
199    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/familysharedsubscriptionextensionineligibleerror)
200    FamilySharedSubscriptionExtensionIneligible = 4030007,
201
202    /// An error that indicates the App Store account wasn’t found.
203    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/accountnotfounderror)
204    AccountNotFound = 4040001,
205
206    /// An error response that indicates the App Store account wasn’t found, but you can try again.
207    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/accountnotfoundretryableerror)
208    AccountNotFoundRetryable = 4040002,
209
210    /// An error that indicates the app wasn’t found.
211    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/appnotfounderror)
212    AppNotFound = 4040003,
213
214    /// An error response that indicates the app wasn’t found, but you can try again.
215    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/appnotfoundretryableerror)
216    AppNotFoundRetryable = 4040004,
217
218    /// An error that indicates an original transaction identifier wasn't found.
219    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/originaltransactionidnotfounderror)
220    OriginalTransactionIdNotFound = 4040005,
221
222    /// An error response that indicates the original transaction identifier wasn’t found, but you can try again.
223    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/originaltransactionidnotfoundretryableerror)
224    OriginalTransactionIdNotFoundRetryable = 4040006,
225
226    /// An error that indicates that the App Store server couldn’t find a notifications URL for your app in this environment.
227    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/servernotificationurlnotfounderror)
228    ServerNotificationUrlNotFound = 4040007,
229
230    /// An error that indicates that the test notification token is expired or the test notification status isn’t available.
231    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/testnotificationnotfounderror)
232    TestNotificationNotFound = 4040008,
233
234    /// An error that indicates the server didn't find a subscription-renewal-date extension request for the request identifier and product identifier you provided.
235    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/statusrequestnotfounderror)
236    StatusRequestNotFound = 4040009,
237
238    /// An error that indicates a transaction identifier wasn't found.
239    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/transactionidnotfounderror)
240    TransactionIdNotFound = 4040010,
241
242    /// An error that indicates that the request exceeded the rate limit.
243    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/ratelimitexceedederror)
244    RateLimitExceeded = 4290000,
245
246    /// An error that indicates a general internal error.
247    ///
248    /// [GeneralInternalError](https://developer.apple.com/documentation/appstoreserverapi/generalinternalerror)
249    GeneralInternal = 5000000,
250
251    /// An error response that indicates an unknown error occurred, but you can try again.
252    ///
253    /// [GeneralInternalRetryableError](https://developer.apple.com/documentation/appstoreserverapi/generalinternalretryableerror)
254    GeneralInternalRetryable = 5000001
255}
256
257#[derive(Debug, Clone, Deserialize, Serialize, Hash)]
258pub struct ErrorPayload {
259    #[serde(rename = "errorCode")]
260    #[serde(default, deserialize_with = "deserialize_maybe_none")]
261    pub error_code: Option<APIError>,
262
263    #[serde(rename = "errorMessage")]
264    pub error_message: Option<String>,
265}
266
267impl ErrorPayload {
268    pub fn raw_error_code(&self) -> Option<i64> {
269        match &self.error_code {
270            None => return None,
271            Some(code) => return Some(code.clone() as i64)
272        }
273    }
274}
275// custom deserializer function
276fn deserialize_maybe_none<'de, D, T: Deserialize<'de>>(
277    deserializer: D,
278) -> Result<Option<T>, D::Error>
279    where
280        D: Deserializer<'de>,
281{
282    // deserialize into local enum
283    if let Ok(value) = Deserialize::deserialize(deserializer) {
284        Ok(value)
285    } else {
286        Ok(None)
287    }
288}