1 | 'use strict';
|
2 |
|
3 | const RETRY_STATUS_CODES = [502, 503, 504];
|
4 |
|
5 | function envVarBasedStrategy(envVar) {
|
6 | return {
|
7 | rertyOnEnvironmentVariableStrategy: () => {
|
8 | return process.env[envVar];
|
9 | },
|
10 | excludeOnEnvironmentVariableStrategy: () => {
|
11 | return !process.env[envVar];
|
12 | },
|
13 | };
|
14 |
|
15 | }
|
16 |
|
17 | function specifcErrorCodesStrategy(err, response = {}) {
|
18 | return RETRY_STATUS_CODES.includes(response.statusCode);
|
19 | }
|
20 |
|
21 |
|
22 | function compositionStrategy(...strategies) {
|
23 |
|
24 | return (err, response, body, options) => {
|
25 | return strategies.some((strategy) => {
|
26 | return strategy(err, response, body, options);
|
27 | });
|
28 | };
|
29 | }
|
30 |
|
31 | module.exports = {
|
32 | envVarBasedStrategy,
|
33 | specifcErrorCodesStrategy,
|
34 | compositionStrategy,
|
35 | RETRY_STATUS_CODES
|
36 | };
|