Telegram.Bot: Error Handling
We have some errors result on SendTextMessage which make throw error exceptions and make slow processes. Is there any solution we safe receive these errors.
https://core.telegram.org/method/messages.sendMessage#return-errors
Exception Message: [Error]: PEER_ID_INVALID
We have 403 FORBIDDEN exception when we SendTextMessage to user which blocked the bot.
https://core.telegram.org/api/errors
Exception Message: Response status code does not indicate success: 403 (Forbidden).
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (10 by maintainers)
I think that the implementation without throwing exceptions would result in a silent fail for most users. As this is undesirable, I am against changing to condition checking instead of exception handling.
It could be implemented in a manner where the two can gracefully live together, by providing a
TryXxxmethod for every method that returnsTask<ResultMessage>, and then reusing that internally.On the other hand, it would be a good idea to include the error description in the
ApiExceptionclass.@amastaneh i think we should indeed throw exeptions. if you really want conditions, just catch those by yourself. Making it conditions would, as @mhverbakel said, result in a silent fail for those user who arent capable of bulding themselves a workaround. Don’t you think it would be better to leave them able to determine the cause of whats happening than you not having to code a single try-catch-loop? if youre sending mass messages, just do it like for example
while(condition) { try { //send Message } catch { //handle Exception } }Since I myself used this library even back since I was a little noob, I prefer simplicity before logical correctness.We need receive these errors normally (not with an exception) and make decision based on these received messages. Anyway you can find out more respectful documents about error handling with Condition Checking is so better than Exception Handling
I think
SendTextMessageneed an output fromResultMessageclass like