@peopl-health/nexus 4.1.1 → 4.1.2
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.
- package/lib/utils/retryUtils.js +14 -16
- package/package.json +1 -1
package/lib/utils/retryUtils.js
CHANGED
|
@@ -41,25 +41,21 @@ function calculateWaitTime(config, retryCount, isRateLimit = false, error = null
|
|
|
41
41
|
return Math.ceil(Math.random() * baseWaitTime);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
const TWILIO_RETRYABLE_CODES = new Set([20429, 20500, 20503]);
|
|
45
|
+
|
|
44
46
|
function isRetryableError(error) {
|
|
45
47
|
if (!error) return false;
|
|
46
|
-
|
|
48
|
+
|
|
47
49
|
const status = error?.status;
|
|
48
50
|
const code = error?.code;
|
|
49
|
-
|
|
50
|
-
if (status === 429 || code === 'rate_limit_exceeded')
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (status >= 500 && status < 600) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
|
|
51
|
+
|
|
52
|
+
if (status === 429 || code === 'rate_limit_exceeded') return true;
|
|
53
|
+
if (status >= 500 && status < 600) return true;
|
|
54
|
+
if (typeof code === 'number' && TWILIO_RETRYABLE_CODES.has(code)) return true;
|
|
55
|
+
|
|
58
56
|
const networkErrorCodes = ['ECONNRESET', 'ETIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED', 'timeout'];
|
|
59
|
-
if (networkErrorCodes.includes(code) || error?.message?.includes('timeout'))
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
57
|
+
if (networkErrorCodes.includes(code) || error?.message?.includes('timeout')) return true;
|
|
58
|
+
|
|
63
59
|
return false;
|
|
64
60
|
}
|
|
65
61
|
|
|
@@ -131,7 +127,9 @@ async function retryWithBackoff(operation, options = {}) {
|
|
|
131
127
|
}
|
|
132
128
|
}
|
|
133
129
|
|
|
134
|
-
module.exports = {
|
|
135
|
-
retryWithBackoff
|
|
130
|
+
module.exports = {
|
|
131
|
+
retryWithBackoff,
|
|
132
|
+
isRetryableError,
|
|
133
|
+
TWILIO_RETRYABLE_CODES
|
|
136
134
|
};
|
|
137
135
|
|