UNPKG

802 BJavaScriptView Raw
1'use strict';
2
3const RETRY_STATUS_CODES = [502, 503, 504];
4
5function envVarBasedStrategy(envVar) {
6 return {
7 rertyOnEnvironmentVariableStrategy: () => {
8 return process.env[envVar];
9 },
10 excludeOnEnvironmentVariableStrategy: () => {
11 return !process.env[envVar];
12 },
13 };
14
15}
16
17function specifcErrorCodesStrategy(err, response = {}) {
18 return RETRY_STATUS_CODES.includes(response.statusCode);
19}
20
21
22function 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
31module.exports = {
32 envVarBasedStrategy,
33 specifcErrorCodesStrategy,
34 compositionStrategy,
35 RETRY_STATUS_CODES
36};