Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions tests/unit-tests/api_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
})

Expand All @@ -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.")
}
})

Expand All @@ -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.")
}
})

Expand Down