Skip to content

Commit

Permalink
fix: support POST for retry-axios (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojito317 committed Sep 22, 2021
1 parent ee47b6e commit 6b055d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/request-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ export class RequestWrapper {
const config: rax.RetryConfig = {
retry: 4, // 4 retries by default
retryDelay: 1000, // 1000 ms (1 sec) initial delay
httpMethodsToRetry: ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT', 'POST'],
instance: axiosInstance,
backoffType: 'exponential',
checkRetryAfter: true, // use Retry-After header first
Expand Down
13 changes: 13 additions & 0 deletions test/unit/retry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ describe('Node Core retries', () => {
scopes.forEach((s) => s.done());
});

it('should retry after we call enableRetries with POST verb', async () => {
const scopes = [
nock(url).post('/').reply(429, undefined),
nock(url).post('/').reply(200, 'retry success!'),
];

parameters.options.method = 'POST';
const result = await service.createRequest(parameters);
expect(result.result).toBe('retry success!');
// ensure all mocks satisfied
scopes.forEach((s) => s.done());
});

it('should not retry more than `maxRetries`', async () => {
const scopes = [
nock(url).get('/').reply(500, undefined),
Expand Down

0 comments on commit 6b055d3

Please sign in to comment.