@@ -54,7 +54,7 @@ public class AppStoreServerAPIClient {
54
54
}
55
55
56
56
guard let url = urlComponents? . url else {
57
- return APIResult . failure ( statusCode: nil , rawApiError: nil , apiError: nil , causedBy: nil )
57
+ return APIResult . failure ( statusCode: nil , rawApiError: nil , apiError: nil , errorMessage : nil , causedBy: nil )
58
58
}
59
59
60
60
var urlRequest = HTTPClientRequest ( url: url. absoluteString)
@@ -82,13 +82,13 @@ public class AppStoreServerAPIClient {
82
82
}
83
83
if response. status. code >= 200 && response. status. code < 300 {
84
84
return APIResult . success ( response: data)
85
- } else if let decodedBody = try ? getJsonDecoder ( ) . decode ( ErrorPayload . self, from: data) , let errorCode = decodedBody. errorCode {
86
- return APIResult . failure ( statusCode: Int ( response. status. code) , rawApiError: errorCode, apiError: APIError . init ( rawValue: errorCode) , causedBy: nil )
85
+ } else if let decodedBody = try ? getJsonDecoder ( ) . decode ( ErrorPayload . self, from: data) , let errorCode = decodedBody. errorCode, let errorMessage = decodedBody . errorMessage {
86
+ return APIResult . failure ( statusCode: Int ( response. status. code) , rawApiError: errorCode, apiError: APIError . init ( rawValue: errorCode) , errorMessage : errorMessage , causedBy: nil )
87
87
} else {
88
- return APIResult . failure ( statusCode: Int ( response. status. code) , rawApiError: nil , apiError: nil , causedBy: nil )
88
+ return APIResult . failure ( statusCode: Int ( response. status. code) , rawApiError: nil , apiError: nil , errorMessage : nil , causedBy: nil )
89
89
}
90
90
} catch ( let error) {
91
- return APIResult . failure ( statusCode: nil , rawApiError: nil , apiError: nil , causedBy: error)
91
+ return APIResult . failure ( statusCode: nil , rawApiError: nil , apiError: nil , errorMessage : nil , causedBy: error)
92
92
}
93
93
}
94
94
@@ -106,10 +106,10 @@ public class AppStoreServerAPIClient {
106
106
let decodedBody = try decoder. decode ( R . self, from: data)
107
107
return APIResult . success ( response: decodedBody)
108
108
} catch ( let error) {
109
- return APIResult . failure ( statusCode: nil , rawApiError: nil , apiError: nil , causedBy: error)
109
+ return APIResult . failure ( statusCode: nil , rawApiError: nil , apiError: nil , errorMessage : nil , causedBy: error)
110
110
}
111
- case . failure( let statusCode, let rawApiError, let apiError, let error) :
112
- return APIResult . failure ( statusCode: statusCode, rawApiError: rawApiError, apiError: apiError, causedBy: error)
111
+ case . failure( let statusCode, let rawApiError, let apiError, let errorMessage , let error) :
112
+ return APIResult . failure ( statusCode: statusCode, rawApiError: rawApiError, apiError: apiError, errorMessage : errorMessage , causedBy: error)
113
113
}
114
114
}
115
115
@@ -118,8 +118,8 @@ public class AppStoreServerAPIClient {
118
118
switch response {
119
119
case . success:
120
120
return APIResult . success ( response: ( ) )
121
- case . failure( let statusCode, let rawApiError, let apiError, let causedBy) :
122
- return APIResult . failure ( statusCode: statusCode, rawApiError: rawApiError, apiError: apiError, causedBy: causedBy)
121
+ case . failure( let statusCode, let rawApiError, let apiError, let errorMessage , let causedBy) :
122
+ return APIResult . failure ( statusCode: statusCode, rawApiError: rawApiError, apiError: apiError, errorMessage : errorMessage , causedBy: causedBy)
123
123
}
124
124
}
125
125
@@ -318,63 +318,282 @@ public class AppStoreServerAPIClient {
318
318
319
319
public enum APIResult < T> {
320
320
case success( response: T )
321
- case failure( statusCode: Int ? , rawApiError: Int64 ? , apiError: APIError ? , causedBy: Error ? )
321
+ case failure( statusCode: Int ? , rawApiError: Int64 ? , apiError: APIError ? , errorMessage : String ? , causedBy: Error ? )
322
322
}
323
323
324
324
public enum APIError : Int64 {
325
+ ///An error that indicates an invalid request.
326
+ ///
327
+ ///[GeneralBadRequestError](https://developer.apple.com/documentation/appstoreserverapi/generalbadrequesterror)
325
328
case generalBadRequest = 4000000
329
+
330
+ ///An error that indicates an invalid app identifier.
331
+ ///
332
+ ///[InvalidAppIdentifierError](https://developer.apple.com/documentation/appstoreserverapi/invalidappidentifiererror)
326
333
case invalidAppIdentifier = 4000002
334
+
335
+ ///An error that indicates an invalid request revision.
336
+ ///
337
+ ///[InvalidRequestRevisionError](https://developer.apple.com/documentation/appstoreserverapi/invalidrequestrevisionerror)
327
338
case invalidRequestRevision = 4000005
339
+
340
+ ///An error that indicates an invalid transaction identifier.
341
+ ///
342
+ ///[InvalidTransactionIdError](https://developer.apple.com/documentation/appstoreserverapi/invalidtransactioniderror)
328
343
case invalidTransactionId = 4000006
344
+
345
+ ///An error that indicates an invalid original transaction identifier.
346
+ ///
347
+ ///[InvalidOriginalTransactionIdError](https://developer.apple.com/documentation/appstoreserverapi/invalidoriginaltransactioniderror)
329
348
case invalidOriginalTransactionId = 4000008
349
+
350
+ ///An error that indicates an invalid extend-by-days value.
351
+ ///
352
+ ///[InvalidExtendByDaysError](https://developer.apple.com/documentation/appstoreserverapi/invalidextendbydayserror)
330
353
case invalidExtendByDays = 4000009
354
+
355
+ ///An error that indicates an invalid reason code.
356
+ ///
357
+ ///[InvalidExtendReasonCodeError](https://developer.apple.com/documentation/appstoreserverapi/invalidextendreasoncodeerror)
331
358
case invalidExtendReasonCode = 4000010
332
- case invalidIdentifier = 4000011
359
+
360
+ ///An error that indicates an invalid request identifier.
361
+ ///
362
+ ///[InvalidRequestIdentifierError](https://developer.apple.com/documentation/appstoreserverapi/invalidrequestidentifiererror)
363
+ case invalidRequestIdentifier = 4000011
364
+
365
+ ///An error that indicates that the start date is earlier than the earliest allowed date.
366
+ ///
367
+ ///[StartDateTooFarInPastError](https://developer.apple.com/documentation/appstoreserverapi/startdatetoofarinpasterror)
333
368
case startDateTooFarInPast = 4000012
369
+
370
+ ///An error that indicates that the end date precedes the start date, or the two dates are equal.
371
+ ///
372
+ ///[StartDateAfterEndDateError](https://developer.apple.com/documentation/appstoreserverapi/startdateafterenddateerror)
334
373
case startDateAfterEndDate = 4000013
374
+
375
+ ///An error that indicates the pagination token is invalid.
376
+ ///
377
+ ///[InvalidPaginationTokenError](https://developer.apple.com/documentation/appstoreserverapi/invalidpaginationtokenerror)
335
378
case invalidPaginationToken = 4000014
379
+
380
+ ///An error that indicates the start date is invalid.
381
+ ///
382
+ ///[InvalidStartDateError](https://developer.apple.com/documentation/appstoreserverapi/invalidstartdateerror)
336
383
case invalidStartDate = 4000015
384
+
385
+ ///An error that indicates the end date is invalid.
386
+ ///
387
+ ///[InvalidEndDateError](https://developer.apple.com/documentation/appstoreserverapi/invalidenddateerror)
337
388
case invalidEndDate = 4000016
389
+
390
+ ///An error that indicates the pagination token expired.
391
+ ///
392
+ ///[PaginationTokenExpiredError](https://developer.apple.com/documentation/appstoreserverapi/paginationtokenexpirederror)
338
393
case paginationTokenExpired = 4000017
394
+
395
+ ///An error that indicates the notification type or subtype is invalid.
396
+ ///
397
+ ///[InvalidNotificationTypeError](https://developer.apple.com/documentation/appstoreserverapi/invalidnotificationtypeerror)
339
398
case invalidNotificationType = 4000018
399
+
400
+ ///An error that indicates the request is invalid because it has too many constraints applied.
401
+ ///
402
+ ///[MultipleFiltersSuppliedError](https://developer.apple.com/documentation/appstoreserverapi/multiplefilterssuppliederror)
340
403
case multipleFiltersSupplied = 4000019
404
+
405
+ ///An error that indicates the test notification token is invalid.
406
+ ///
407
+ ///[InvalidTestNotificationTokenError](https://developer.apple.com/documentation/appstoreserverapi/invalidtestnotificationtokenerror)
341
408
case invalidTestNotificationToken = 4000020
409
+
410
+ ///An error that indicates an invalid sort parameter.
411
+ ///
412
+ ///[InvalidSortError](https://developer.apple.com/documentation/appstoreserverapi/invalidsorterror)
342
413
case invalidSort = 4000021
414
+
415
+ ///An error that indicates an invalid product type parameter.
416
+ ///
417
+ ///[InvalidProductTypeError](https://developer.apple.com/documentation/appstoreserverapi/invalidproducttypeerror)
343
418
case invalidProductType = 4000022
419
+
420
+ ///An error that indicates the product ID parameter is invalid.
421
+ ///
422
+ ///[InvalidProductIdError](https://developer.apple.com/documentation/appstoreserverapi/invalidproductiderror)
344
423
case invalidProductId = 4000023
424
+
425
+ ///An error that indicates an invalid subscription group identifier.
426
+ ///
427
+ ///[InvalidSubscriptionGroupIdentifierError](https://developer.apple.com/documentation/appstoreserverapi/invalidsubscriptiongroupidentifiererror)
345
428
case invalidSubscriptionGroupIdentifier = 4000024
429
+
430
+ ///An error that indicates the query parameter exclude-revoked is invalid.
431
+ ///
432
+ ///[InvalidExcludeRevokedError](https://developer.apple.com/documentation/appstoreserverapi/invalidexcluderevokederror)
346
433
case invalidExcludeRevoked = 4000025
434
+
435
+ ///An error that indicates an invalid in-app ownership type parameter.
436
+ ///
437
+ ///[InvalidInAppOwnershipTypeError](https://developer.apple.com/documentation/appstoreserverapi/invalidinappownershiptypeerror)
347
438
case invalidInAppOwnershipType = 4000026
439
+
440
+ ///An error that indicates a required storefront country code is empty.
441
+ ///
442
+ ///[InvalidEmptyStorefrontCountryCodeListError](https://developer.apple.com/documentation/appstoreserverapi/invalidemptystorefrontcountrycodelisterror)
348
443
case invalidEmptyStorefrontCountryCodeList = 4000027
444
+
445
+ ///An error that indicates a storefront code is invalid.
446
+ ///
447
+ ///[InvalidStorefrontCountryCodeError](https://developer.apple.com/documentation/appstoreserverapi/invalidstorefrontcountrycodeerror)
349
448
case invalidStorefrontCountryCode = 4000028
350
- case invaildRevoked = 4000030
449
+
450
+ ///An error that indicates the revoked parameter contains an invalid value.
451
+ ///
452
+ ///[InvalidRevokedError](https://developer.apple.com/documentation/appstoreserverapi/invalidrevokederror)
453
+ case invalidRevoked = 4000030
454
+
455
+ ///An error that indicates the status parameter is invalid.
456
+ ///
457
+ ///[InvalidStatusError](https://developer.apple.com/documentation/appstoreserverapi/invalidstatuserror)
351
458
case invalidStatus = 4000031
459
+
460
+ ///An error that indicates the value of the account tenure field is invalid.
461
+ ///
462
+ ///[InvalidAccountTenureError](https://developer.apple.com/documentation/appstoreserverapi/invalidaccounttenureerror)
352
463
case invalidAccountTenure = 4000032
464
+
465
+ ///An error that indicates the value of the app account token field is invalid.
466
+ ///
467
+ ///[InvalidAppAccountTokenError](https://developer.apple.com/documentation/appstoreserverapi/invalidappaccounttokenerror)
353
468
case invalidAppAccountToken = 4000033
469
+
470
+ ///An error that indicates the value of the consumption status field is invalid.
471
+ ///
472
+ ///[InvalidConsumptionStatusError](https://developer.apple.com/documentation/appstoreserverapi/invalidconsumptionstatuserror)
354
473
case invalidConsumptionStatus = 4000034
474
+
475
+ ///An error that indicates the customer consented field is invalid or doesn’t indicate that the customer consented.
476
+ ///
477
+ ///[InvalidCustomerConsentedError](https://developer.apple.com/documentation/appstoreserverapi/invalidcustomerconsentederror)
355
478
case invalidCustomerConsented = 4000035
479
+
480
+ ///An error that indicates the value in the delivery status field is invalid.
481
+ ///
482
+ ///[InvalidDeliveryStatusError](https://developer.apple.com/documentation/appstoreserverapi/invaliddeliverystatuserror)
356
483
case invalidDeliveryStatus = 4000036
484
+
485
+ ///An error that indicates the value in the lifetime dollars purchased field is invalid.
486
+ ///
487
+ ///[InvalidLifetimeDollarsPurchasedError](https://developer.apple.com/documentation/appstoreserverapi/invalidlifetimedollarspurchasederror)
357
488
case invalidLifetimeDollarsPurchased = 4000037
489
+
490
+ ///An error that indicates the value in the lifetime dollars refunded field is invalid.
491
+ ///
492
+ ///[InvalidLifetimeDollarsRefundedError](https://developer.apple.com/documentation/appstoreserverapi/invalidlifetimedollarsrefundederror)
358
493
case invalidLifetimeDollarsRefunded = 4000038
494
+
495
+ ///An error that indicates the value in the platform field is invalid.
496
+ ///
497
+ ///[InvalidPlatformError](https://developer.apple.com/documentation/appstoreserverapi/invalidplatformerror)
359
498
case invalidPlatform = 4000039
499
+
500
+ ///An error that indicates the value in the playtime field is invalid.
501
+ ///
502
+ ///[InvalidPlayTimeError](https://developer.apple.com/documentation/appstoreserverapi/invalidplaytimeerror)
360
503
case invalidPlayTime = 4000040
504
+
505
+ ///An error that indicates the value in the sample content provided field is invalid.
506
+ ///
507
+ ///[InvalidSampleContentProvidedError](https://developer.apple.com/documentation/appstoreserverapi/invalidsamplecontentprovidederror)
361
508
case invalidSampleContentProvided = 4000041
509
+
510
+ ///An error that indicates the value in the user status field is invalid.
511
+ ///
512
+ ///[InvalidUserStatusError](https://developer.apple.com/documentation/appstoreserverapi/invaliduserstatuserror)
362
513
case invalidUserStatus = 4000042
514
+
515
+ ///An error that indicates the transaction identifier doesn’t represent a consumable in-app purchase.
516
+ ///
517
+ ///[InvalidTransactionNotConsumableError](https://developer.apple.com/documentation/appstoreserverapi/invalidtransactionnotconsumableerror)
363
518
case invalidTransactionNotConsumable = 4000043
519
+
520
+ ///An error that indicates the subscription doesn't qualify for a renewal-date extension due to its subscription state.
521
+ ///
522
+ ///[SubscriptionExtensionIneligibleError](https://developer.apple.com/documentation/appstoreserverapi/subscriptionextensionineligibleerror)
364
523
case subscriptionExtensionIneligible = 4030004
524
+
525
+ ///An error that indicates the subscription doesn’t qualify for a renewal-date extension because it has already received the maximum extensions.
526
+ ///
527
+ ///[SubscriptionMaxExtensionError](https://developer.apple.com/documentation/appstoreserverapi/subscriptionmaxextensionerror)
365
528
case subscriptionMaxExtension = 4030005
529
+
530
+ ///An error that indicates a subscription isn't directly eligible for a renewal date extension because the user obtained it through Family Sharing.
531
+ ///
532
+ ///[FamilySharedSubscriptionExtensionIneligibleError](https://developer.apple.com/documentation/appstoreserverapi/familysharedsubscriptionextensionineligibleerror)
366
533
case familySharedSubscriptionExtensionIneligible = 4030007
534
+
535
+ ///An error that indicates the App Store account wasn’t found.
536
+ ///
537
+ ///[AccountNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/accountnotfounderror)
367
538
case accountNotFound = 4040001
539
+
540
+ ///An error response that indicates the App Store account wasn’t found, but you can try again.
541
+ ///
542
+ ///[AccountNotFoundRetryableError](https://developer.apple.com/documentation/appstoreserverapi/accountnotfoundretryableerror)
368
543
case accountNotFoundRetryable = 4040002
544
+
545
+ ///An error that indicates the app wasn’t found.
546
+ ///
547
+ ///[AppNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/appnotfounderror)
369
548
case appNotFound = 4040003
549
+
550
+ ///An error response that indicates the app wasn’t found, but you can try again.
551
+ ///
552
+ ///[AppNotFoundRetryableError](https://developer.apple.com/documentation/appstoreserverapi/appnotfoundretryableerror)
370
553
case appNotFoundRetryable = 4040004
554
+
555
+ ///An error that indicates an original transaction identifier wasn't found.
556
+ ///
557
+ ///[OriginalTransactionIdNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/originaltransactionidnotfounderror)
371
558
case originalTransactionIdNotFound = 4040005
559
+
560
+ ///An error response that indicates the original transaction identifier wasn’t found, but you can try again.
561
+ ///
562
+ ///[OriginalTransactionIdNotFoundRetryableError](https://developer.apple.com/documentation/appstoreserverapi/originaltransactionidnotfoundretryableerror)
372
563
case originalTransactionIdNotFoundRetryable = 4040006
564
+
565
+ ///An error that indicates that the App Store server couldn’t find a notifications URL for your app in this environment.
566
+ ///
567
+ ///[ServerNotificationUrlNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/servernotificationurlnotfounderror)
373
568
case serverNotificationUrlNotFound = 4040007
569
+
570
+ ///An error that indicates that the test notification token is expired or the test notification status isn’t available.
571
+ ///
572
+ ///[TestNotificationNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/testnotificationnotfounderror)
374
573
case testNotificationNotFound = 4040008
574
+
575
+ ///An error that indicates the server didn't find a subscription-renewal-date extension request for the request identifier and product identifier you provided.
576
+ ///
577
+ ///[StatusRequestNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/statusrequestnotfounderror)
375
578
case statusRequestNotFound = 4040009
579
+
580
+ ///An error that indicates a transaction identifier wasn't found.
581
+ ///
582
+ ///[TransactionIdNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/transactionidnotfounderror)
376
583
case transactionIdNotFound = 4040010
584
+
585
+ ///An error that indicates that the request exceeded the rate limit.
586
+ ///
587
+ ///[RateLimitExceededError](https://developer.apple.com/documentation/appstoreserverapi/ratelimitexceedederror)
377
588
case rateLimitExceeded = 4290000
589
+
590
+ ///An error that indicates a general internal error.
591
+ ///
592
+ ///[GeneralInternalError](https://developer.apple.com/documentation/appstoreserverapi/generalinternalerror)
378
593
case generalInternal = 5000000
594
+
595
+ ///An error response that indicates an unknown error occurred, but you can try again.
596
+ ///
597
+ ///[GeneralInternalRetryableError](https://developer.apple.com/documentation/appstoreserverapi/generalinternalretryableerror)
379
598
case generalInternalRetryable = 5000001
380
599
}
0 commit comments