mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: avoid unhandled promise timeout errors
This commit is contained in:
@@ -187,7 +187,7 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
let onRecv: (json) => void
|
||||
let onErr: (err) => void
|
||||
try {
|
||||
return await promiseTimeout<T>(timeoutMs,
|
||||
const result = await promiseTimeout<T>(timeoutMs,
|
||||
(resolve, reject) => {
|
||||
onRecv = resolve
|
||||
onErr = err => {
|
||||
@@ -199,6 +199,8 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
ws.off('error', onErr)
|
||||
},
|
||||
)
|
||||
|
||||
return result as any
|
||||
} finally {
|
||||
ws.off(`TAG:${msgId}`, onRecv!)
|
||||
ws.off('close', onErr!) // if the socket closes, you'll never receive the message
|
||||
@@ -213,11 +215,13 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
}
|
||||
|
||||
const msgId = node.attrs.id
|
||||
const wait = waitForMessage(msgId, timeoutMs)
|
||||
|
||||
await sendNode(node)
|
||||
const [result] = await Promise.all([
|
||||
waitForMessage(msgId, timeoutMs),
|
||||
await sendNode(node)
|
||||
])
|
||||
|
||||
|
||||
const result = await (wait as Promise<BinaryNode>)
|
||||
if('tag' in result) {
|
||||
assertNodeErrorFree(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user