chore: do not throw unhandled error on send messages again, log error

This commit is contained in:
Adhiraj Singh
2021-12-10 11:22:06 +05:30
parent 3cfde73718
commit 7db5bb5d9a

View File

@@ -465,10 +465,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
}) })
const sendMessagesAgain = async(key: proto.IMessageKey, ids: string[]) => { const sendMessagesAgain = async(key: proto.IMessageKey, ids: string[]) => {
const participant = key.participant || key.remoteJid
await assertSession(participant, true)
logger.debug({ key, ids }, 'recv retry request, forced new session')
const msgs = await Promise.all( const msgs = await Promise.all(
ids.map(id => ( ids.map(id => (
@@ -476,6 +472,11 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
)) ))
) )
const participant = key.participant || key.remoteJid
await assertSession(participant, true)
logger.debug({ participant }, 'forced new session for retry recp')
for(let i = 0; i < msgs.length;i++) { for(let i = 0; i < msgs.length;i++) {
if(msgs[i]) { if(msgs[i]) {
await relayMessage(key.remoteJid, msgs[i], { await relayMessage(key.remoteJid, msgs[i], {
@@ -489,6 +490,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} }
const handleReceipt = async(node: BinaryNode) => { const handleReceipt = async(node: BinaryNode) => {
let shouldAck = true
const { attrs, content } = node const { attrs, content } = node
const remoteJid = attrs.recipient || attrs.from const remoteJid = attrs.recipient || attrs.from
const fromMe = attrs.recipient ? false : true const fromMe = attrs.recipient ? false : true
@@ -515,10 +517,19 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
} }
if(attrs.type === 'retry') { if(attrs.type === 'retry') {
await sendMessagesAgain(key, ids) try {
logger.debug({ attrs }, 'recv retry request')
await sendMessagesAgain(key, ids)
} catch(error) {
logger.error({ key, ids, trace: error.stack }, 'error in sending message again')
shouldAck = false
}
}
if(shouldAck) {
await sendMessageAck(node, { class: 'receipt', type: attrs.type })
} }
await sendMessageAck(node, { class: 'receipt', type: attrs.type })
} }
ws.on('CB:receipt', handleReceipt) ws.on('CB:receipt', handleReceipt)