1 | /**
|
2 | * -------------------------------------------------------------------------------------------
|
3 | * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
|
4 | * See License in the project root for license information.
|
5 | * -------------------------------------------------------------------------------------------
|
6 | */
|
7 | /**
|
8 | * @module RetryHandler
|
9 | */
|
10 | import { Context } from "../IContext";
|
11 | import { Middleware } from "./IMiddleware";
|
12 | import { RetryHandlerOptions } from "./options/RetryHandlerOptions";
|
13 | /**
|
14 | * @class
|
15 | * @implements Middleware
|
16 | * Class for RetryHandler
|
17 | */
|
18 | export declare class RetryHandler implements Middleware {
|
19 | /**
|
20 | * @private
|
21 | * @static
|
22 | * A list of status codes that needs to be retried
|
23 | */
|
24 | private static RETRY_STATUS_CODES;
|
25 | /**
|
26 | * @private
|
27 | * @static
|
28 | * A member holding the name of retry attempt header
|
29 | */
|
30 | private static RETRY_ATTEMPT_HEADER;
|
31 | /**
|
32 | * @private
|
33 | * @static
|
34 | * A member holding the name of retry after header
|
35 | */
|
36 | private static RETRY_AFTER_HEADER;
|
37 | /**
|
38 | * @private
|
39 | * A member to hold next middleware in the middleware chain
|
40 | */
|
41 | private nextMiddleware;
|
42 | /**
|
43 | * @private
|
44 | * A member holding the retry handler options
|
45 | */
|
46 | private options;
|
47 | /**
|
48 | * @public
|
49 | * @constructor
|
50 | * To create an instance of RetryHandler
|
51 | * @param {RetryHandlerOptions} [options = new RetryHandlerOptions()] - The retry handler options value
|
52 | * @returns An instance of RetryHandler
|
53 | */
|
54 | constructor(options?: RetryHandlerOptions);
|
55 | /**
|
56 | *
|
57 | * @private
|
58 | * To check whether the response has the retry status code
|
59 | * @param {Response} response - The response object
|
60 | * Whether the response has retry status code or not
|
61 | */
|
62 | private isRetry;
|
63 | /**
|
64 | * @private
|
65 | * To check whether the payload is buffered or not
|
66 | * @param {RequestInfo} request - The url string or the request object value
|
67 | * @param {FetchOptions} options - The options of a request
|
68 | * @returns Whether the payload is buffered or not
|
69 | */
|
70 | private isBuffered;
|
71 | /**
|
72 | * @private
|
73 | * To get the delay for a retry
|
74 | * @param {Response} response - The response object
|
75 | * @param {number} retryAttempts - The current attempt count
|
76 | * @param {number} delay - The delay value in seconds
|
77 | * @returns A delay for a retry
|
78 | */
|
79 | private getDelay;
|
80 | /**
|
81 | * @private
|
82 | * To get an exponential back off value
|
83 | * @param {number} attempts - The current attempt count
|
84 | * @returns An exponential back off value
|
85 | */
|
86 | private getExponentialBackOffTime;
|
87 | /**
|
88 | * @private
|
89 | * @async
|
90 | * To add delay for the execution
|
91 | * @param {number} delaySeconds - The delay value in seconds
|
92 | * @returns Nothing
|
93 | */
|
94 | private sleep;
|
95 | private getOptions;
|
96 | /**
|
97 | * @private
|
98 | * @async
|
99 | * To execute the middleware with retries
|
100 | * @param {Context} context - The context object
|
101 | * @param {number} retryAttempts - The current attempt count
|
102 | * @param {RetryHandlerOptions} options - The retry middleware options instance
|
103 | * @returns A Promise that resolves to nothing
|
104 | */
|
105 | private executeWithRetry;
|
106 | /**
|
107 | * @public
|
108 | * @async
|
109 | * To execute the current middleware
|
110 | * @param {Context} context - The context object of the request
|
111 | * @returns A Promise that resolves to nothing
|
112 | */
|
113 | execute(context: Context): Promise<void>;
|
114 | /**
|
115 | * @public
|
116 | * To set the next middleware in the chain
|
117 | * @param {Middleware} next - The middleware instance
|
118 | * @returns Nothing
|
119 | */
|
120 | setNext(next: Middleware): void;
|
121 | }
|