@@ -11,15 +11,15 @@ const DEFAULT_RETRY_ATTEMPTS = 3;
11
11
/**
12
12
* Configuration of the retry middleware
13
13
*/
14
- export interface RetryOptions < ResponseType = Response > {
14
+ export interface RetryOptions < TResponse = Response > {
15
15
/**
16
16
* Function to decide if the request should be retried.
17
17
*
18
18
* @param response Optional response of the request.
19
19
* @param error Optional error thrown from previous attempts.
20
20
* @returns True if the request should be retried.
21
21
*/
22
- retryDecider : ( response ?: ResponseType , error ?: unknown ) => Promise < boolean > ;
22
+ retryDecider : ( response ?: TResponse , error ?: unknown ) => Promise < boolean > ;
23
23
/**
24
24
* Function to compute the delay in milliseconds before the next retry based
25
25
* on the number of attempts.
@@ -40,14 +40,17 @@ export interface RetryOptions<ResponseType = Response> {
40
40
/**
41
41
* Retry middleware
42
42
*/
43
- export const retryMiddleware = < Input = Request , Output = Response > (
44
- options : RetryOptions < Output >
43
+ export const retryMiddleware = < TInput = Request , TOutput = Response > (
44
+ options : RetryOptions < TOutput >
45
45
) => {
46
46
if ( options . maxAttempts < 1 ) {
47
47
throw new Error ( 'maxAttempts must be greater than 0' ) ;
48
48
}
49
- return ( next : MiddlewareHandler < Input , Output > , context : MiddlewareContext ) =>
50
- async function retryMiddleware ( request : Input ) {
49
+ return (
50
+ next : MiddlewareHandler < TInput , TOutput > ,
51
+ context : MiddlewareContext
52
+ ) =>
53
+ async function retryMiddleware ( request : TInput ) {
51
54
const {
52
55
maxAttempts = DEFAULT_RETRY_ATTEMPTS ,
53
56
retryDecider,
@@ -56,7 +59,7 @@ export const retryMiddleware = <Input = Request, Output = Response>(
56
59
} = options ;
57
60
let error : Error ;
58
61
let attemptsCount = context . attemptsCount ?? 0 ;
59
- let response : Output ;
62
+ let response : TOutput ;
60
63
while ( ! abortSignal ?. aborted && attemptsCount < maxAttempts ) {
61
64
error = undefined ;
62
65
response = undefined ;
0 commit comments