Skip to content

Commit e11cef7

Browse files
committed
chore: moved getMaxAttempts to different functions
1 parent 796e680 commit e11cef7

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/middleware-retry/src/defaultStrategy.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ export class StandardRetryStrategy implements RetryStrategy {
9191
);
9292
}
9393

94+
private async getMaxAttempts() {
95+
let maxAttemptsStr;
96+
try {
97+
maxAttemptsStr = await this.maxAttemptsProvider();
98+
} catch (error) {
99+
maxAttemptsStr = "3";
100+
}
101+
const maxAttempts = parseInt(maxAttemptsStr);
102+
return Number.isNaN(maxAttempts) ? 3 : maxAttempts;
103+
}
104+
94105
async retry<Input extends object, Ouput extends MetadataBearer>(
95106
next: FinalizeHandler<Input, Ouput>,
96107
args: FinalizeHandlerArguments<Input>
@@ -99,16 +110,7 @@ export class StandardRetryStrategy implements RetryStrategy {
99110
let attempts = 0;
100111
let totalDelay = 0;
101112

102-
const maxAttempts = await (async () => {
103-
let maxAttemptsStr;
104-
try {
105-
maxAttemptsStr = await this.maxAttemptsProvider();
106-
} catch (error) {
107-
maxAttemptsStr = "3";
108-
}
109-
const maxAttempts = parseInt(maxAttemptsStr);
110-
return Number.isNaN(maxAttempts) ? 3 : maxAttempts;
111-
})();
113+
const maxAttempts = await this.getMaxAttempts();
112114

113115
const { request } = args;
114116
if (HttpRequest.isInstance(request)) {

0 commit comments

Comments
 (0)