Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: exposes original axios error object #479

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions src/helpers/api-client-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ export class ApiClientHelpers {
credentials,
),
)
}

axiosInstance.interceptors.response.use(
(response: AxiosResponse) => response,
(error: AxiosError) => {
throw apiErrorFactory(error)
},
)
axiosInstance.interceptors.response.use(
(response: AxiosResponse) => response,
(error: AxiosError) => {
throw apiErrorFactory(error)
},
)
}

return axiosInstance
}
Expand Down
25 changes: 24 additions & 1 deletion test/types/errors/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
assertMarketplaceHasSellingPartner,
} from '@scaleleap/amazon-marketplaces'
import { jestPollyContext } from '@scaleleap/jest-polly'
import { AxiosError } from 'axios'
import axios, { AxiosError } from 'axios'
import { StatusCodes } from 'http-status-codes'
import { toNumber } from 'lodash'

Expand Down Expand Up @@ -199,4 +199,27 @@ describe(`client`, () => {
'ERR_BAD_RESPONSE',
)
})

it('should allow to access origin error', async () => {
expect.assertions(1)

const { CA } = amazonMarketplaces
assertMarketplaceHasSellingPartner(CA)

const configuration: APIConfigurationParameters = {
accessToken: 'Atza|...',
region: CA.sellingPartner.region.awsRegion,
axios,
}

jestPollyContext.polly.server
.any(`${CA.sellingPartner.region.endpoint}/sellers/v1/marketplaceParticipations`)
.intercept((request, response) => {
response.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR)
})

const client = new SellersApiClient(configuration)

await expect(client.getMarketplaceParticipations()).rejects.toThrow(AxiosError)
})
})