1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | exports.RetryHandlerOptions = void 0;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var RetryHandlerOptions = (function () {
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
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 |
|
65 |
|
66 |
|
67 |
|
68 | RetryHandlerOptions.prototype.getMaxDelay = function () {
|
69 | return RetryHandlerOptions.MAX_DELAY;
|
70 | };
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 | RetryHandlerOptions.DEFAULT_DELAY = 3;
|
77 | |
78 |
|
79 |
|
80 |
|
81 |
|
82 | RetryHandlerOptions.DEFAULT_MAX_RETRIES = 3;
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 | RetryHandlerOptions.MAX_DELAY = 180;
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 | RetryHandlerOptions.MAX_MAX_RETRIES = 10;
|
95 | |
96 |
|
97 |
|
98 |
|
99 | RetryHandlerOptions.defaultShouldRetry = function () { return true; };
|
100 | return RetryHandlerOptions;
|
101 | }());
|
102 | exports.RetryHandlerOptions = RetryHandlerOptions;
|
103 |
|
\ | No newline at end of file |