UNPKG

4.15 kBJavaScriptView Raw
1"use strict";
2/**
3 * -------------------------------------------------------------------------------------------
4 * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
5 * See License in the project root for license information.
6 * -------------------------------------------------------------------------------------------
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.RetryHandlerOptions = void 0;
10/**
11 * @class
12 * @implements MiddlewareOptions
13 * Class for RetryHandlerOptions
14 */
15var RetryHandlerOptions = /** @class */ (function () {
16 /**
17 * @public
18 * @constructor
19 * To create an instance of RetryHandlerOptions
20 * @param {number} [delay = RetryHandlerOptions.DEFAULT_DELAY] - The delay value in seconds
21 * @param {number} [maxRetries = RetryHandlerOptions.DEFAULT_MAX_RETRIES] - The maxRetries value
22 * @param {ShouldRetry} [shouldRetry = RetryHandlerOptions.DEFAULT_SHOULD_RETRY] - The shouldRetry callback function
23 * @returns An instance of RetryHandlerOptions
24 */
25 function RetryHandlerOptions(delay, maxRetries, shouldRetry) {
26 if (delay === void 0) { delay = RetryHandlerOptions.DEFAULT_DELAY; }
27 if (maxRetries === void 0) { maxRetries = RetryHandlerOptions.DEFAULT_MAX_RETRIES; }
28 if (shouldRetry === void 0) { shouldRetry = RetryHandlerOptions.defaultShouldRetry; }
29 if (delay > RetryHandlerOptions.MAX_DELAY && maxRetries > RetryHandlerOptions.MAX_MAX_RETRIES) {
30 var error = new Error("Delay and MaxRetries should not be more than ".concat(RetryHandlerOptions.MAX_DELAY, " and ").concat(RetryHandlerOptions.MAX_MAX_RETRIES));
31 error.name = "MaxLimitExceeded";
32 throw error;
33 }
34 else if (delay > RetryHandlerOptions.MAX_DELAY) {
35 var error = new Error("Delay should not be more than ".concat(RetryHandlerOptions.MAX_DELAY));
36 error.name = "MaxLimitExceeded";
37 throw error;
38 }
39 else if (maxRetries > RetryHandlerOptions.MAX_MAX_RETRIES) {
40 var error = new Error("MaxRetries should not be more than ".concat(RetryHandlerOptions.MAX_MAX_RETRIES));
41 error.name = "MaxLimitExceeded";
42 throw error;
43 }
44 else if (delay < 0 && maxRetries < 0) {
45 var error = new Error("Delay and MaxRetries should not be negative");
46 error.name = "MinExpectationNotMet";
47 throw error;
48 }
49 else if (delay < 0) {
50 var error = new Error("Delay should not be negative");
51 error.name = "MinExpectationNotMet";
52 throw error;
53 }
54 else if (maxRetries < 0) {
55 var error = new Error("MaxRetries should not be negative");
56 error.name = "MinExpectationNotMet";
57 throw error;
58 }
59 this.delay = Math.min(delay, RetryHandlerOptions.MAX_DELAY);
60 this.maxRetries = Math.min(maxRetries, RetryHandlerOptions.MAX_MAX_RETRIES);
61 this.shouldRetry = shouldRetry;
62 }
63 /**
64 * @public
65 * To get the maximum delay
66 * @returns A maximum delay
67 */
68 RetryHandlerOptions.prototype.getMaxDelay = function () {
69 return RetryHandlerOptions.MAX_DELAY;
70 };
71 /**
72 * @private
73 * @static
74 * A member holding default delay value in seconds
75 */
76 RetryHandlerOptions.DEFAULT_DELAY = 3;
77 /**
78 * @private
79 * @static
80 * A member holding default maxRetries value
81 */
82 RetryHandlerOptions.DEFAULT_MAX_RETRIES = 3;
83 /**
84 * @private
85 * @static
86 * A member holding maximum delay value in seconds
87 */
88 RetryHandlerOptions.MAX_DELAY = 180;
89 /**
90 * @private
91 * @static
92 * A member holding maximum maxRetries value
93 */
94 RetryHandlerOptions.MAX_MAX_RETRIES = 10;
95 /**
96 * @private
97 * A member holding default shouldRetry callback
98 */
99 RetryHandlerOptions.defaultShouldRetry = function () { return true; };
100 return RetryHandlerOptions;
101}());
102exports.RetryHandlerOptions = RetryHandlerOptions;
103//# sourceMappingURL=RetryHandlerOptions.js.map
\No newline at end of file