Don't merge yet: Keep on listening to Telegram's updates even if requests with telegram server fail #40
No reviewers
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: thereadme/node-telegram-api#40
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Finally managed to hunt down this edge case that would freeze entire telegram bot if one getUpdates() request fails.
Edit: I'm not really certain about this solution, in terms if it should exist at all.
On one side, this PR provides a convenience to the end module user by simplifying error recovery and guarantees bot's ability to continue to listen to new incomming messages.
On the other, the end user loses ability to take matters into their own hands because of always resolved promise. There could be cases when module user might want to handle connection error with telegram's server in another way.
What would be your suggestion @mdibaiee?
Hey!
Why not run the
poll
on afinally
clause? See:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally
https://github.com/es-shims/Promise.prototype.finally
Your
.then
handler implementation is spot on where.then
handler usesresponse
data,.finally
is generally used at the end of the promise chain, it does not receive any arguments into it's handler.Also, you implemented a decent round-robin
getUpdates
listener by just recursing current promise chain. Hence, semantically.finally
should not belong in poll.js file but in user's codebase that deals with bot.start() chain breakage issues instead. Even then, as a user, extendingbot.start()
with.finally
doesn't make sense either (due to recursive promise chaining).My suggestion is either to merge this PR and let people read about how this module deals with edge case scenario when
getUpdates
returns a rejection or.. completely ignore/close this PR and maybe just to add some explanation with a tiny example in the wiki how to revive bot's listener in case telegram's server decides to break apart:Sorry, for my autism :D, hope this sheds the light a bit more.
I see your point, I really don't think users should copy paste a snippet like the one you mentioned to handle errors, that's not user-friendly.
Let's keep this change, but also emit an
error
event when we catch an exception, what do you say? 😁Hi @mdibaiee, sorry for a late response. I was leaning to the same conclusion. Had a bit of thinking yesterday about a potential solution for such cases.
My idea is to add additional method to the bot class
bot.onError(cb)
that triggerscb
function every time there's an error for any method insideapi.js
method. This way, bot can keep on resuminggetUpdates
recursion infinitely, but also a user can tap into errors and decide what to do case-by-case basis.I will update my PR in couple of days time for your review to better understand of what do I mean.
@laurynas-karvelis Yeah, that's a good idea, but we don't need an additional method, bot is already an instance of
EventEmitter
, so justbot.emit('error', e)
. And then users can use bot.on('error', cb)`Sweet, I'll do a PR update today or tomorrow then if you'd like.
@laurynas-karvelis that would be awesome, thanks!
I've updated my PR. Could you have a look at it @mdibaiee?
Thanks a lot!
published
telegram-api@2.0.0.
Sweet! Thank you for the merge @mdibaiee!