presidium 3.4.6 → 3.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const sleep = require('./sleep')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @name RetryAwsErrors
|
|
3
5
|
*
|
|
@@ -9,8 +11,20 @@
|
|
|
9
11
|
|
|
10
12
|
const RetryAwsErrors = function (func, context, name) {
|
|
11
13
|
return function retriesAwsErrors(...args) {
|
|
12
|
-
return func.apply(context, args).catch(error => {
|
|
13
|
-
if (
|
|
14
|
+
return func.apply(context, args).catch(async error => {
|
|
15
|
+
if (
|
|
16
|
+
error.name == 'ThrottlingException'
|
|
17
|
+
|| error.name == 'RateExceeded'
|
|
18
|
+
|| error.name == 'TooManyRequestsException'
|
|
19
|
+
|| error.code == 408
|
|
20
|
+
|| error.code == 429
|
|
21
|
+
|| error.code == 500
|
|
22
|
+
|| error.code == 502
|
|
23
|
+
|| error.code == 503
|
|
24
|
+
|| error.code == 504
|
|
25
|
+
|| error.code == 509
|
|
26
|
+
) {
|
|
27
|
+
await sleep(1000)
|
|
14
28
|
return retriesAwsErrors(...args)
|
|
15
29
|
}
|
|
16
30
|
throw error
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const Test = require('./thunk-test')
|
|
2
|
+
const RetryAwsErrors = require('./RetryAwsErrors')
|
|
3
|
+
|
|
4
|
+
// TODO
|
|
5
|
+
const throwThrottlingException = () => {
|
|
6
|
+
const error = new Error('Rate exceeded')
|
|
7
|
+
error.name = 'ThrottlingException'
|
|
8
|
+
throw error
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const test = new Test('RetryAwsErrors', RetryAwsErrors)
|
|
12
|
+
|
|
13
|
+
test.case(throwThrottlingException)
|
|
14
|
+
|
|
15
|
+
if (process.argv[1] == __filename) {
|
|
16
|
+
test()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = test
|