I have a function that looks like
async function longPoll() {
let timeout = 0
try {
// perform longPoll tasks
let response = await axios.get(config.url)
const data = response.data && response.data.data
if (!Array.isArray(data)) {
return
}
await Promise.all(data.map(async(item) => {
try {
// send message via WhatsApp using 'whatsapp-web.js'
let chatId = getChatId(item)
let text = getText(item)
await client.sendMessage(chatId, text)
} catch (e) {
// some logging
return
}
try {
// report sending is ok
let response = await axios.get(config.confirmationUrl)
} catch (e) {
// some logging
}
}))
} catch (e) {
if (e.response) {
let status = e.response.status
let statusText = e.response.statusText
console.error(`Server response ${status} ${statusText}`)
} else if (e.request) {
console.error('No response from server.')
} else {
console.error('Failed to create request.')
}
timeout = 5000
} finally {
setTimeout(longPoll, timeout)
}
}
longPoll() // kick off
In the beginning, it runs fine. After a while, longPoll()
is no longer called. Why is it so?
I'm using NodeJS v16.14.0 with axios v0.19
Notes:
- I have found the cause. See my own answer.
- Repro steps available in my comment
- I undeleted this question for informational & sharing purpose