Skip to content

Commit cd79396

Browse files
Add errorMessage to APIException
1 parent a15c7ef commit cd79396

File tree

3 files changed

+256
-17
lines changed

3 files changed

+256
-17
lines changed

NOTICE.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,19 @@ Copyright © 2023 Apple Inc. and the SwiftASN1 project authors
4949
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
5050
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5151

52+
_____________________
53+
54+
AsyncHttpClient Project ( async-http-client )
55+
Copyright (c) 2014-2023 AsyncHttpClient Project. All rights reserved.
56+
57+
Licensed under the Apache License, Version 2.0 (the "License");
58+
you may not use this file except in compliance with the License.
59+
You may obtain a copy of the License at
60+
61+
http://www.apache.org/licenses/LICENSE-2.0
62+
63+
Unless required by applicable law or agreed to in writing, software
64+
distributed under the License is distributed on an "AS IS" BASIS,
65+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66+
See the License for the specific language governing permissions and
67+
limitations under the License.

Sources/AppStoreServerLibrary/AppStoreServerAPIClient.swift

Lines changed: 232 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class AppStoreServerAPIClient {
5454
}
5555

5656
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)
5858
}
5959

6060
var urlRequest = HTTPClientRequest(url: url.absoluteString)
@@ -82,13 +82,13 @@ public class AppStoreServerAPIClient {
8282
}
8383
if response.status.code >= 200 && response.status.code < 300 {
8484
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)
8787
} 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)
8989
}
9090
} 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)
9292
}
9393
}
9494

@@ -106,10 +106,10 @@ public class AppStoreServerAPIClient {
106106
let decodedBody = try decoder.decode(R.self, from: data)
107107
return APIResult.success(response: decodedBody)
108108
} 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)
110110
}
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)
113113
}
114114
}
115115

@@ -118,8 +118,8 @@ public class AppStoreServerAPIClient {
118118
switch response {
119119
case .success:
120120
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)
123123
}
124124
}
125125

@@ -318,63 +318,282 @@ public class AppStoreServerAPIClient {
318318

319319
public enum APIResult<T> {
320320
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?)
322322
}
323323

324324
public enum APIError: Int64 {
325+
///An error that indicates an invalid request.
326+
///
327+
///[GeneralBadRequestError](https://developer.apple.com/documentation/appstoreserverapi/generalbadrequesterror)
325328
case generalBadRequest = 4000000
329+
330+
///An error that indicates an invalid app identifier.
331+
///
332+
///[InvalidAppIdentifierError](https://developer.apple.com/documentation/appstoreserverapi/invalidappidentifiererror)
326333
case invalidAppIdentifier = 4000002
334+
335+
///An error that indicates an invalid request revision.
336+
///
337+
///[InvalidRequestRevisionError](https://developer.apple.com/documentation/appstoreserverapi/invalidrequestrevisionerror)
327338
case invalidRequestRevision = 4000005
339+
340+
///An error that indicates an invalid transaction identifier.
341+
///
342+
///[InvalidTransactionIdError](https://developer.apple.com/documentation/appstoreserverapi/invalidtransactioniderror)
328343
case invalidTransactionId = 4000006
344+
345+
///An error that indicates an invalid original transaction identifier.
346+
///
347+
///[InvalidOriginalTransactionIdError](https://developer.apple.com/documentation/appstoreserverapi/invalidoriginaltransactioniderror)
329348
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)
330353
case invalidExtendByDays = 4000009
354+
355+
///An error that indicates an invalid reason code.
356+
///
357+
///[InvalidExtendReasonCodeError](https://developer.apple.com/documentation/appstoreserverapi/invalidextendreasoncodeerror)
331358
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)
333368
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)
334373
case startDateAfterEndDate = 4000013
374+
375+
///An error that indicates the pagination token is invalid.
376+
///
377+
///[InvalidPaginationTokenError](https://developer.apple.com/documentation/appstoreserverapi/invalidpaginationtokenerror)
335378
case invalidPaginationToken = 4000014
379+
380+
///An error that indicates the start date is invalid.
381+
///
382+
///[InvalidStartDateError](https://developer.apple.com/documentation/appstoreserverapi/invalidstartdateerror)
336383
case invalidStartDate = 4000015
384+
385+
///An error that indicates the end date is invalid.
386+
///
387+
///[InvalidEndDateError](https://developer.apple.com/documentation/appstoreserverapi/invalidenddateerror)
337388
case invalidEndDate = 4000016
389+
390+
///An error that indicates the pagination token expired.
391+
///
392+
///[PaginationTokenExpiredError](https://developer.apple.com/documentation/appstoreserverapi/paginationtokenexpirederror)
338393
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)
339398
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)
340403
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)
341408
case invalidTestNotificationToken = 4000020
409+
410+
///An error that indicates an invalid sort parameter.
411+
///
412+
///[InvalidSortError](https://developer.apple.com/documentation/appstoreserverapi/invalidsorterror)
342413
case invalidSort = 4000021
414+
415+
///An error that indicates an invalid product type parameter.
416+
///
417+
///[InvalidProductTypeError](https://developer.apple.com/documentation/appstoreserverapi/invalidproducttypeerror)
343418
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)
344423
case invalidProductId = 4000023
424+
425+
///An error that indicates an invalid subscription group identifier.
426+
///
427+
///[InvalidSubscriptionGroupIdentifierError](https://developer.apple.com/documentation/appstoreserverapi/invalidsubscriptiongroupidentifiererror)
345428
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)
346433
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)
347438
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)
348443
case invalidEmptyStorefrontCountryCodeList = 4000027
444+
445+
///An error that indicates a storefront code is invalid.
446+
///
447+
///[InvalidStorefrontCountryCodeError](https://developer.apple.com/documentation/appstoreserverapi/invalidstorefrontcountrycodeerror)
349448
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)
351458
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)
352463
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)
353468
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)
354473
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)
355478
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)
356483
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)
357488
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)
358493
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)
359498
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)
360503
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)
361508
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)
362513
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)
363518
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)
364523
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)
365528
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)
366533
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)
367538
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)
368543
case accountNotFoundRetryable = 4040002
544+
545+
///An error that indicates the app wasn’t found.
546+
///
547+
///[AppNotFoundError](https://developer.apple.com/documentation/appstoreserverapi/appnotfounderror)
369548
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)
370553
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)
371558
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)
372563
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)
373568
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)
374573
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)
375578
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)
376583
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)
377588
case rateLimitExceeded = 4290000
589+
590+
///An error that indicates a general internal error.
591+
///
592+
///[GeneralInternalError](https://developer.apple.com/documentation/appstoreserverapi/generalinternalerror)
378593
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)
379598
case generalInternalRetryable = 5000001
380599
}

0 commit comments

Comments
 (0)