diff --git a/index.ts b/index.ts index c045d4c..07710e3 100644 --- a/index.ts +++ b/index.ts @@ -143,9 +143,10 @@ export class AppStoreServerAPIClient { try { const responseBody = await response.json() const errorCode = responseBody['errorCode'] + const errorMessage = responseBody['errorMessage'] if (errorCode) { - throw new APIException(response.status, errorCode) + throw new APIException(response.status, errorCode, errorMessage) } throw new APIException(response.status) @@ -369,11 +370,13 @@ export class AppStoreServerAPIClient { export class APIException extends Error { public httpStatusCode: number public apiError: number | APIError | null + public errorMessage: string | null - constructor(httpStatusCode: number, apiError: number | null = null) { + constructor(httpStatusCode: number, apiError: number | null = null, errorMessage: string | null = null) { super() this.httpStatusCode = httpStatusCode this.apiError = apiError + this.errorMessage = errorMessage } } @@ -437,7 +440,7 @@ export enum APIError { * * {@link https://developer.apple.com/documentation/appstoreserverapi/invalidrequestidentifiererror InvalidRequestIdentifierError} */ - INVALID_IDENTIFIER = 4000011, + INVALID_REQUEST_IDENTIFIER = 4000011, /** * An error that indicates that the start date is earlier than the earliest allowed date. diff --git a/tests/unit-tests/api_client.test.ts b/tests/unit-tests/api_client.test.ts index 17cb9e0..16566ad 100644 --- a/tests/unit-tests/api_client.test.ts +++ b/tests/unit-tests/api_client.test.ts @@ -417,6 +417,7 @@ describe('The api client ', () => { let error = e as APIException expect(error.httpStatusCode).toBe(500) expect(error.apiError).toBe(APIError.GENERAL_INTERNAL) + expect(error.errorMessage).toBe("An unknown error occurred.") } }) @@ -435,6 +436,7 @@ describe('The api client ', () => { let error = e as APIException expect(error.httpStatusCode).toBe(429) expect(error.apiError).toBe(APIError.RATE_LIMIT_EXCEEDED) + expect(error.errorMessage).toBe("Rate limit exceeded.") } }) @@ -453,6 +455,7 @@ describe('The api client ', () => { let error = e as APIException expect(error.httpStatusCode).toBe(400) expect(error.apiError).toBe(9990000) + expect(error.errorMessage).toBe("Testing error.") } })