From dfc6bebb244d5ce2c8ec00569b4847accf141665 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 11 Dec 2023 18:36:31 -0600 Subject: [PATCH] Add errorMessage to APIException Add JavaDocs for the error codes --- .../itunes/storekit/client/APIError.java | 330 ++++++++++++++++++ .../itunes/storekit/client/APIException.java | 39 ++- .../client/AppStoreServerAPIClient.java | 14 +- .../client/AppStoreServerAPIClientTest.java | 8 + 4 files changed, 372 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/apple/itunes/storekit/client/APIError.java b/src/main/java/com/apple/itunes/storekit/client/APIError.java index 8d284306..d5701df2 100644 --- a/src/main/java/com/apple/itunes/storekit/client/APIError.java +++ b/src/main/java/com/apple/itunes/storekit/client/APIError.java @@ -10,60 +10,390 @@ * See the specific documentation for each endpoint to learn more about what codes are possible from each endpoint. */ public enum APIError { + /** + * An error that indicates an invalid request. + * + * @see GeneralBadRequestError + */ GENERAL_BAD_REQUEST(4000000L), + + /** + * An error that indicates an invalid app identifier. + * + * @see InvalidAppIdentifierError + */ INVALID_APP_IDENTIFIER(4000002L), + + /** + * An error that indicates an invalid request revision. + * + * @see InvalidRequestRevisionError + */ INVALID_REQUEST_REVISION(4000005L), + + /** + * An error that indicates an invalid transaction identifier. + * + * @see InvalidTransactionIdError + */ INVALID_TRANSACTION_ID(4000006L), + + /** + * An error that indicates an invalid original transaction identifier. + * + * @see InvalidOriginalTransactionIdError + */ INVALID_ORIGINAL_TRANSACTION_ID(4000008L), + + /** + * An error that indicates an invalid extend-by-days value. + * + * @see InvalidExtendByDaysError + */ INVALID_EXTEND_BY_DAYS(4000009L), + + /** + * An error that indicates an invalid reason code. + * + * @see InvalidExtendReasonCodeError + */ INVALID_EXTEND_REASON_CODE(4000010L), + + /** + * An error that indicates an invalid request identifier. + * + * @see InvalidRequestIdentifierError + */ INVALID_IDENTIFIER(4000011L), + + /** + * An error that indicates that the start date is earlier than the earliest allowed date. + * + * @see StartDateTooFarInPastError + */ START_DATE_TOO_FAR_IN_PAST(4000012L), + + /** + * An error that indicates that the end date precedes the start date, or the two dates are equal. + * + * @see StartDateAfterEndDateError + */ START_DATE_AFTER_END_DATE(4000013L), + + /** + * An error that indicates the pagination token is invalid. + * + * @see InvalidPaginationTokenError + */ INVALID_PAGINATION_TOKEN(4000014L), + + /** + * An error that indicates the start date is invalid. + * + * @see InvalidStartDateError + */ INVALID_START_DATE(4000015L), + + /** + * An error that indicates the end date is invalid. + * + * @see InvalidEndDateError + */ INVALID_END_DATE(4000016L), + + /** + * An error that indicates the pagination token expired. + * + * @see PaginationTokenExpiredError + */ PAGINATION_TOKEN_EXPIRED(4000017L), + + /** + * An error that indicates the notification type or subtype is invalid. + * + * @see InvalidNotificationTypeError + */ INVALID_NOTIFICATION_TYPE(4000018L), + + /** + * An error that indicates the request is invalid because it has too many constraints applied. + * + * @see MultipleFiltersSuppliedError + */ MULTIPLE_FILTERS_SUPPLIED(4000019L), + + /** + * An error that indicates the test notification token is invalid. + * + * @see InvalidTestNotificationTokenError + */ INVALID_TEST_NOTIFICATION_TOKEN(4000020L), + + /** + * An error that indicates an invalid sort parameter. + * + * @see InvalidSortError + */ INVALID_SORT(4000021L), + + /** + * An error that indicates an invalid product type parameter. + * + * @see InvalidProductTypeError + */ INVALID_PRODUCT_TYPE(4000022L), + + /** + * An error that indicates the product ID parameter is invalid. + * + * @see InvalidProductIdError + */ INVALID_PRODUCT_ID(4000023L), + + /** + * An error that indicates an invalid subscription group identifier. + * + * @see InvalidSubscriptionGroupIdentifierError + */ INVALID_SUBSCRIPTION_GROUP_IDENTIFIER(4000024L), + + /** + * An error that indicates the query parameter exclude-revoked is invalid. + * + * @see InvalidExcludeRevokedError + */ + @Deprecated INVALID_EXCLUDE_REVOKED(4000025L), + + /** + * An error that indicates an invalid in-app ownership type parameter. + * + * @see InvalidInAppOwnershipTypeError + */ INVALID_IN_APP_OWNERSHIP_TYPE(4000026L), + + /** + * An error that indicates a required storefront country code is empty. + * + * @see InvalidEmptyStorefrontCountryCodeListError + */ INVALID_EMPTY_STOREFRONT_COUNTRY_CODE_LIST(4000027L), + + /** + * An error that indicates a storefront code is invalid. + * + * @see InvalidStorefrontCountryCodeError + */ INVALID_STOREFRONT_COUNTRY_CODE(4000028L), + + /** + * An error that indicates the revoked parameter contains an invalid value. + * + * @see InvalidRevokedError + */ INVALID_REVOKED(4000030L), + + /** + * An error that indicates the status parameter is invalid. + * + * @see InvalidStatusError + */ INVALID_STATUS(4000031L), + + /** + * An error that indicates the value of the account tenure field is invalid. + * + * @see InvalidAccountTenureError + */ INVALID_ACCOUNT_TENURE(4000032L), + + /** + * An error that indicates the value of the app account token field is invalid. + * + * @see InvalidAppAccountTokenError + */ INVALID_APP_ACCOUNT_TOKEN(4000033L), + + /** + * An error that indicates the value of the consumption status field is invalid. + * + * @see InvalidConsumptionStatusError + */ INVALID_CONSUMPTION_STATUS(4000034L), + + /** + * An error that indicates the customer consented field is invalid or doesn’t indicate that the customer consented. + * + * @see InvalidCustomerConsentedError + */ INVALID_CUSTOMER_CONSENTED(4000035L), + + /** + * An error that indicates the value in the delivery status field is invalid. + * + * @see InvalidDeliveryStatusError + */ INVALID_DELIVERY_STATUS(4000036L), + + /** + * An error that indicates the value in the lifetime dollars purchased field is invalid. + * + * @see InvalidLifetimeDollarsPurchasedError + */ INVALID_LIFETIME_DOLLARS_PURCHASED(4000037L), + + /** + * An error that indicates the value in the lifetime dollars refunded field is invalid. + * + * @see InvalidLifetimeDollarsRefundedError + */ INVALID_LIFETIME_DOLLARS_REFUNDED(4000038L), + + /** + * An error that indicates the value in the platform field is invalid. + * + * @see InvalidPlatformError + */ INVALID_PLATFORM(4000039L), + + /** + * An error that indicates the value in the playtime field is invalid. + * + * @see InvalidPlayTimeError + */ INVALID_PLAY_TIME(4000040L), + + /** + * An error that indicates the value in the sample content provided field is invalid. + * + * @see InvalidSampleContentProvidedError + */ INVALID_SAMPLE_CONTENT_PROVIDED(4000041L), + + /** + * An error that indicates the value in the user status field is invalid. + * + * @see InvalidUserStatusError + */ INVALID_USER_STATUS(4000042L), + + /** + * An error that indicates the transaction identifier doesn’t represent a consumable in-app purchase. + * + * @see InvalidTransactionNotConsumableError + */ INVALID_TRANSACTION_NOT_CONSUMABLE(4000043L), + + /** + * An error that indicates the subscription doesn't qualify for a renewal-date extension due to its subscription state. + * + * @see SubscriptionExtensionIneligibleError + */ SUBSCRIPTION_EXTENSION_INELIGIBLE(4030004L), + + /** + * An error that indicates the subscription doesn’t qualify for a renewal-date extension because it has already received the maximum extensions. + * + * @see SubscriptionMaxExtensionError + */ SUBSCRIPTION_MAX_EXTENSION(4030005L), + + /** + * An error that indicates a subscription isn't directly eligible for a renewal date extension because the user obtained it through Family Sharing. + * + * @see FamilySharedSubscriptionExtensionIneligibleError + */ FAMILY_SHARED_SUBSCRIPTION_EXTENSION_INELIGIBLE(4030007L), + + /** + * An error that indicates the App Store account wasn’t found. + * + * @see AccountNotFoundError + */ ACCOUNT_NOT_FOUND(4040001L), + + /** + * An error response that indicates the App Store account wasn’t found, but you can try again. + * + * @see AccountNotFoundRetryableError + */ ACCOUNT_NOT_FOUND_RETRYABLE(4040002L), + + /** + * An error that indicates the app wasn’t found. + * + * @see AppNotFoundError + */ APP_NOT_FOUND(4040003L), + + /** + * An error response that indicates the app wasn’t found, but you can try again. + * + * @see AppNotFoundRetryableError + */ APP_NOT_FOUND_RETRYABLE(4040004L), + + /** + * An error that indicates an original transaction identifier wasn't found. + * + * @see OriginalTransactionIdNotFoundError + */ ORIGINAL_TRANSACTION_ID_NOT_FOUND(4040005L), + + /** + * An error response that indicates the original transaction identifier wasn’t found, but you can try again. + * + * @see OriginalTransactionIdNotFoundRetryableError + */ ORIGINAL_TRANSACTION_ID_NOT_FOUND_RETRYABLE(4040006L), + + /** + * An error that indicates that the App Store server couldn’t find a notifications URL for your app in this environment. + * + * @see ServerNotificationUrlNotFoundError + */ SERVER_NOTIFICATION_URL_NOT_FOUND(4040007L), + + /** + * An error that indicates that the test notification token is expired or the test notification status isn’t available. + * + * @see TestNotificationNotFoundError + */ TEST_NOTIFICATION_NOT_FOUND(4040008L), + + /** + * An error that indicates the server didn't find a subscription-renewal-date extension request for the request identifier and product identifier you provided. + * + * @see StatusRequestNotFoundError + */ STATUS_REQUEST_NOT_FOUND(4040009L), + + /** + * An error that indicates a transaction identifier wasn't found. + * + * @see TransactionIdNotFoundError + */ TRANSACTION_ID_NOT_FOUND(4040010L), + + /** + * An error that indicates that the request exceeded the rate limit. + * + * @see RateLimitExceededError + */ RATE_LIMIT_EXCEEDED(4290000L), + + /** + * An error that indicates a general internal error. + * + * @see GeneralInternalError + */ GENERAL_INTERNAL(5000000L), + + /** + * An error response that indicates an unknown error occurred, but you can try again. + * + * @see GeneralInternalRetryableError + */ GENERAL_INTERNAL_RETRYABLE(5000001L); private final long errorCode; diff --git a/src/main/java/com/apple/itunes/storekit/client/APIException.java b/src/main/java/com/apple/itunes/storekit/client/APIException.java index cb97f695..4d227ad2 100644 --- a/src/main/java/com/apple/itunes/storekit/client/APIException.java +++ b/src/main/java/com/apple/itunes/storekit/client/APIException.java @@ -9,21 +9,35 @@ */ public class APIException extends Exception { private final int httpStatusCode; - private final Long apiError; + private final Long apiErrorCode; + private final String apiErrorMessage; + + public APIException(int httpStatusCode, Exception cause) { + super("Failed to call API with httpStatusCode=" + httpStatusCode, cause); + this.httpStatusCode = httpStatusCode; + this.apiErrorCode = null; + this.apiErrorMessage = null; + } public APIException(int httpStatusCode) { + super("Failed to call API with httpStatusCode=" + httpStatusCode); this.httpStatusCode = httpStatusCode; - this.apiError = null; + this.apiErrorCode = null; + this.apiErrorMessage = null; } - public APIException(int httpStatusCode, APIError apiError) { + public APIException(int httpStatusCode, APIError apiError, String apiErrorMessage) { + super("Failed to call API with error=\"" + apiErrorMessage + "\""); this.httpStatusCode = httpStatusCode; - this.apiError = apiError != null ? apiError.errorCode() : null; + this.apiErrorCode = apiError != null ? apiError.errorCode() : null; + this.apiErrorMessage = apiErrorMessage; } - public APIException(int httpStatusCode, Long rawApiError) { + public APIException(int httpStatusCode, Long rawApiError, String apiErrorMessage) { + super("Failed to call API with error=\"" + apiErrorMessage + "\""); this.httpStatusCode = httpStatusCode; - this.apiError = rawApiError; + this.apiErrorCode = rawApiError; + this.apiErrorMessage = apiErrorMessage; } public int getHttpStatusCode() { @@ -31,18 +45,23 @@ public int getHttpStatusCode() { } public APIError getApiError() { - return apiError != null ? APIError.fetchErrorResponseFromErrorCode(apiError) : null; + return apiErrorCode != null ? APIError.fetchErrorResponseFromErrorCode(apiErrorCode) : null; } public Long getRawApiError() { - return apiError; + return apiErrorCode; + } + + public String getApiErrorMessage() { + return apiErrorMessage; } @Override public String toString() { return "APIException{" + "httpStatusCode=" + httpStatusCode + - ", apiError=" + apiError + - "} " + super.toString(); + ", apiError=" + apiErrorCode + + ", apiErrorMessage='" + apiErrorMessage + '\'' + + '}'; } } diff --git a/src/main/java/com/apple/itunes/storekit/client/AppStoreServerAPIClient.java b/src/main/java/com/apple/itunes/storekit/client/AppStoreServerAPIClient.java index 0b2d203d..681c556f 100644 --- a/src/main/java/com/apple/itunes/storekit/client/AppStoreServerAPIClient.java +++ b/src/main/java/com/apple/itunes/storekit/client/AppStoreServerAPIClient.java @@ -115,10 +115,8 @@ protected T makeHttpCall(String path, String method, Map T makeHttpCall(String path, String method, Map