@peopl-health/nexus 4.1.0 → 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.
|
@@ -136,13 +136,13 @@ class TwilioProvider extends MessageProvider {
|
|
|
136
136
|
result = await this.twilioClient.messages.create(sends[i]);
|
|
137
137
|
} catch (twilioErr) {
|
|
138
138
|
await recordDeliveryAttempt({
|
|
139
|
-
messageData, messageId: pending?._id, kind,
|
|
139
|
+
messageData, messageId: pending?._id, kind, body: sends[i].body || null,
|
|
140
140
|
errorSource: 'twilio_sync',
|
|
141
141
|
errorCode: twilioErr.code, errorMessage: twilioErr.message
|
|
142
142
|
});
|
|
143
143
|
throw twilioErr;
|
|
144
144
|
}
|
|
145
|
-
await recordDeliveryAttempt({ messageData, messageId: pending?._id, twilioResult: result, kind });
|
|
145
|
+
await recordDeliveryAttempt({ messageData, messageId: pending?._id, twilioResult: result, kind, body: sends[i].body || null });
|
|
146
146
|
if (i < sends.length - 1) await new Promise(r => setTimeout(r, 100));
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -4,7 +4,7 @@ const { Message } = require('../models/messageModel');
|
|
|
4
4
|
const { DeliveryAttempt } = require('../models/deliveryAttemptModel');
|
|
5
5
|
|
|
6
6
|
async function recordDeliveryAttempt({
|
|
7
|
-
messageData = null, messageId = null, twilioResult = null, kind,
|
|
7
|
+
messageData = null, messageId = null, twilioResult = null, kind, body = null,
|
|
8
8
|
errorSource = null, errorCode = null, errorMessage = null
|
|
9
9
|
}) {
|
|
10
10
|
const sid = twilioResult?.sid || null;
|
|
@@ -30,6 +30,7 @@ async function recordDeliveryAttempt({
|
|
|
30
30
|
kind,
|
|
31
31
|
twilioSid: sid,
|
|
32
32
|
contentSid: messageData?.contentSid || null,
|
|
33
|
+
body,
|
|
33
34
|
status,
|
|
34
35
|
errorSource,
|
|
35
36
|
errorCode,
|
|
@@ -148,7 +148,8 @@ class TemplateApprovalJob extends BaseJob {
|
|
|
148
148
|
messageData: { contentSid: templateSid },
|
|
149
149
|
messageId: message._id,
|
|
150
150
|
twilioResult: { sid: recoveryMessageId, status: sendResult?.status },
|
|
151
|
-
kind: 'recovery_template'
|
|
151
|
+
kind: 'recovery_template',
|
|
152
|
+
body: message.body
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
provider.deleteTemplate(templateSid).catch((deleteErr) =>
|
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
|
|