gramjs
gramjs copied to clipboard
Invoke not throwing an error when client is disconnected
I have a snippet of code that's responsible for sending messages to channels which works fine when the client is connected but doesn't throw any errors when the client looses connection and the message gets lost without any notice.
I've tried with .then/.catch/.finally and with awaiting .invoke and I never get any errors when connection is lost.
The snippet (very verbose, just testing):
telegramClient.invoke(
new Api.messages.SendMessage({
peer: channelPeer,
message,
})
).then((value) => {
console.log("INVOKE THEN", messageData.message, JSON.stringify(value, Object.getOwnPropertyNames(value)));
}).catch((e) => {
console.log("INVOKE CATCH ERROR:", messageData.message, JSON.stringify(e, Object.getOwnPropertyNames(e)));
}).finally(() => {
console.log("INVOKE FINALLY", messageData.message);
});
Example workflow:
- Create client and connect
- Send message
- Receive message and .then or result if await
- Lose internet connection (disable LAN/WAN/pull cable)
- Send message
- Message is lost without any notice or error
- Re-establish internet connection
- Send message
- Receive message and .then or result if await
My problem is in steps 4-6. What do I have to do to be alerted about message failed to be sent? Or perhaps being retried when the connection is re-established.
I have waited 10+ minutes after re-establishing connection and the message never appears (nor any errors).