Skip to content

Commit 0816564

Browse files
committed
chore: rename maxRetries to maxAttempts
1 parent 70621d9 commit 0816564

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

packages/middleware-retry/src/configurations.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ export interface RetryInputConfig {
55
/**
66
* The maximum number of times requests that encounter potentially transient failures should be retried
77
*/
8-
maxRetries?: number;
8+
maxAttempts?: number;
99
/**
1010
* The strategy to retry the request. Using built-in exponential backoff strategy by default.
1111
*/
1212
retryStrategy?: RetryStrategy;
1313
}
1414
export interface RetryResolvedConfig {
15-
maxRetries: number;
15+
maxAttempts: number;
1616
retryStrategy: RetryStrategy;
1717
}
1818
export function resolveRetryConfig<T>(
1919
input: T & RetryInputConfig
2020
): T & RetryResolvedConfig {
21-
const maxRetries = input.maxRetries === undefined ? 3 : input.maxRetries;
21+
const maxAttempts = input.maxAttempts === undefined ? 3 : input.maxAttempts;
2222
return {
2323
...input,
24-
maxRetries,
24+
maxAttempts,
2525
retryStrategy:
26-
input.retryStrategy || new ExponentialBackOffStrategy(maxRetries)
26+
input.retryStrategy || new ExponentialBackOffStrategy(maxAttempts)
2727
};
2828
}

packages/middleware-retry/src/defaultStrategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class ExponentialBackOffStrategy implements RetryStrategy {
4040
private delayDecider: DelayDecider = defaultDelayDecider
4141
) {}
4242
private shouldRetry(error: SdkError, retryAttempted: number) {
43-
return retryAttempted < this.maxRetries && this.retryDecider(error);
43+
return retryAttempted < this.maxAttempts && this.retryDecider(error);
4444
}
4545

4646
async retry<Input extends object, Ouput extends MetadataBearer>(

packages/middleware-retry/src/index.spec.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import { SdkError } from "@aws-sdk/smithy-client";
1212
describe("retryMiddleware", () => {
1313
it("should not retry when the handler completes successfully", async () => {
1414
const next = jest.fn().mockResolvedValue({ output: { $metadata: {} } });
15-
const retryHandler = retryMiddleware(resolveRetryConfig({ maxRetries: 0 }))(
16-
next
17-
);
15+
const retryHandler = retryMiddleware(
16+
resolveRetryConfig({ maxAttempts: 0 })
17+
)(next);
1818

1919
const {
2020
output: { $metadata }
@@ -26,28 +26,28 @@ describe("retryMiddleware", () => {
2626
});
2727

2828
it("should stop retrying when the the maximum number of retries is reached", async () => {
29-
const maxRetries = 3;
29+
const maxAttempts = 3;
3030
const error = new Error();
3131
error.name = "ProvisionedThroughputExceededException";
3232
const next = jest.fn().mockRejectedValue(error);
33-
const retryHandler = retryMiddleware(resolveRetryConfig({ maxRetries }))(
33+
const retryHandler = retryMiddleware(resolveRetryConfig({ maxAttempts }))(
3434
next
3535
);
3636

3737
await expect(
3838
retryHandler({ input: {}, request: new HttpRequest({}) })
3939
).rejects.toMatchObject(error);
4040

41-
expect(next.mock.calls.length).toBe(maxRetries + 1);
41+
expect(next.mock.calls.length).toBe(maxAttempts + 1);
4242
});
4343

4444
it("should not retry if the error is not transient", async () => {
4545
const error = new Error();
4646
error.name = "ValidationException";
4747
const next = jest.fn().mockRejectedValue(error);
48-
const retryHandler = retryMiddleware(resolveRetryConfig({ maxRetries: 3 }))(
49-
next
50-
);
48+
const retryHandler = retryMiddleware(
49+
resolveRetryConfig({ maxAttempts: 3 })
50+
)(next);
5151

5252
await expect(
5353
retryHandler({ input: {}, request: new HttpRequest({}) })
@@ -69,15 +69,17 @@ describe("retryMiddleware", () => {
6969

7070
jest.mock("./delayDecider");
7171

72-
const maxRetries = 3;
72+
const maxAttempts = 3;
7373
const delayDeciderMock = jest.spyOn(
7474
delayDeciderModule,
7575
"defaultDelayDecider"
7676
);
7777
const retryDecider: RetryDecider = (error: SdkError) => true;
78-
const strategy = new ExponentialBackOffStrategy(maxRetries, retryDecider);
78+
const strategy = new ExponentialBackOffStrategy(maxAttempts, {
79+
retryDecider
80+
});
7981
const retryHandler = retryMiddleware({
80-
maxRetries,
82+
maxAttempts: maxAttempts,
8183
retryStrategy: strategy
8284
})(next);
8385

packages/middleware-retry/src/retryMiddleware.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ import {
99
} from "@aws-sdk/types";
1010
import { RetryResolvedConfig } from "./configurations";
1111

12-
export function retryMiddleware(options: RetryResolvedConfig) {
13-
return <Output extends MetadataBearer = MetadataBearer>(
14-
next: FinalizeHandler<any, Output>
15-
): FinalizeHandler<any, Output> => async (
16-
args: FinalizeHandlerArguments<any>
17-
): Promise<FinalizeHandlerOutput<Output>> => {
18-
return options.retryStrategy.retry(next, args);
19-
};
20-
}
12+
export const retryMiddleware = (options: RetryResolvedConfig) => <
13+
Output extends MetadataBearer = MetadataBearer
14+
>(
15+
next: FinalizeHandler<any, Output>
16+
): FinalizeHandler<any, Output> => async (
17+
args: FinalizeHandlerArguments<any>
18+
): Promise<FinalizeHandlerOutput<Output>> =>
19+
options.retryStrategy.retry(next, args);
2120

2221
export const retryMiddlewareOptions: FinalizeRequestHandlerOptions &
2322
AbsoluteLocation = {
@@ -31,7 +30,7 @@ export const getRetryPlugin = (
3130
options: RetryResolvedConfig
3231
): Pluggable<any, any> => ({
3332
applyToStack: clientStack => {
34-
if (options.maxRetries > 0) {
33+
if (options.maxAttempts > 0) {
3534
clientStack.add(retryMiddleware(options), retryMiddlewareOptions);
3635
}
3736
}

packages/types/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface RetryStrategy {
6161
* the maximum number of times requests that encounter potentially
6262
* transient failures should be retried
6363
*/
64-
maxRetries: number;
64+
maxAttempts: number;
6565
/**
6666
* the retry behavior the will invoke the next handler and handle the retry accordingly.
6767
* This function should also update the $metadata from the response accordingly.

0 commit comments

Comments
 (0)