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 subscription doesn't qualify for a renewal-date extension due to its subscription state.
176    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/subscriptionextensionineligibleerror)
177    SubscriptionExtensionIneligible = 4030004,
178
179    /// An error that indicates the subscription doesn’t qualify for a renewal-date extension because it has already received the maximum extensions.
180    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/subscriptionmaxextensionerror)
181    SubscriptionMaxExtension = 4030005,
182
183    /// An error that indicates a subscription isn't directly eligible for a renewal date extension because the user obtained it through Family Sharing.
184    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/familysharedsubscriptionextensionineligibleerror)
185    FamilySharedSubscriptionExtensionIneligible = 4030007,
186
187    /// An error that indicates the App Store account wasn’t found.
188    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/accountnotfounderror)
189    AccountNotFound = 4040001,
190
191    /// An error response that indicates the App Store account wasn’t found, but you can try again.
192    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/accountnotfoundretryableerror)
193    AccountNotFoundRetryable = 4040002,
194
195    /// An error that indicates the app wasn’t found.
196    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/appnotfounderror)
197    AppNotFound = 4040003,
198
199    /// An error response that indicates the app wasn’t found, but you can try again.
200    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/appnotfoundretryableerror)
201    AppNotFoundRetryable = 4040004,
202
203    /// An error that indicates an original transaction identifier wasn't found.
204    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/originaltransactionidnotfounderror)
205    OriginalTransactionIdNotFound = 4040005,
206
207    /// An error response that indicates the original transaction identifier wasn’t found, but you can try again.
208    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/originaltransactionidnotfoundretryableerror)
209    OriginalTransactionIdNotFoundRetryable = 4040006,
210
211    /// An error that indicates that the App Store server couldn’t find a notifications URL for your app in this environment.
212    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/servernotificationurlnotfounderror)
213    ServerNotificationUrlNotFound = 4040007,
214
215    /// An error that indicates that the test notification token is expired or the test notification status isn’t available.
216    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/testnotificationnotfounderror)
217    TestNotificationNotFound = 4040008,
218
219    /// An error that indicates the server didn't find a subscription-renewal-date extension request for the request identifier and product identifier you provided.
220    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/statusrequestnotfounderror)
221    StatusRequestNotFound = 4040009,
222
223    /// An error that indicates a transaction identifier wasn't found.
224    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/transactionidnotfounderror)
225    TransactionIdNotFound = 4040010,
226
227    /// An error that indicates that the request exceeded the rate limit.
228    /// [Documentation](https://developer.apple.com/documentation/appstoreserverapi/ratelimitexceedederror)
229    RateLimitExceeded = 4290000,
230
231    /// An error that indicates a general internal error.
232    ///
233    /// [GeneralInternalError](https://developer.apple.com/documentation/appstoreserverapi/generalinternalerror)
234    GeneralInternal = 5000000,
235
236    /// An error response that indicates an unknown error occurred, but you can try again.
237    ///
238    /// [GeneralInternalRetryableError](https://developer.apple.com/documentation/appstoreserverapi/generalinternalretryableerror)
239    GeneralInternalRetryable = 5000001
240}
241
242#[derive(Debug, Clone, Deserialize, Serialize, Hash)]
243pub struct ErrorPayload {
244    #[serde(rename = "errorCode")]
245    #[serde(default, deserialize_with = "deserialize_maybe_none")]
246    pub error_code: Option<APIError>,
247
248    #[serde(rename = "errorMessage")]
249    pub error_message: Option<String>,
250}
251
252impl ErrorPayload {
253    pub fn raw_error_code(&self) -> Option<i64> {
254        match &self.error_code {
255            None => return None,
256            Some(code) => return Some(code.clone() as i64)
257        }
258    }
259}
260// custom deserializer function
261fn deserialize_maybe_none<'de, D, T: Deserialize<'de>>(
262    deserializer: D,
263) -> Result<Option<T>, D::Error>
264    where
265        D: Deserializer<'de>,
266{
267    // deserialize into local enum
268    if let Ok(value) = Deserialize::deserialize(deserializer) {
269        Ok(value)
270    } else {
271        Ok(None)
272    }
273}