Updated Exception Handling (markdown)

Rahiel Kasim 2017-05-08 20:51:12 +02:00
parent 58341a9d7d
commit b27b5ea64a

@ -1,6 +1,6 @@
In `python-telegram-bot`, all Telegram-related errors are encapsulated in the `TelegramError` exception class and its subclasses.
To simplify error handling, any `TelegramError` that is raised in one of your handlers (or while calling `getUpdates` in the `Updater`) is forwarded to all registered error handlers, so you can react to them. You can register an error handler by calling `Dispatcher.add_error_handler(callback)`, where `callback` is a function that takes the arguments `bot, update, error`. `update` will be the update that caused the error and `error` the `TelegramError` that was raised.
To simplify error handling, any `TelegramError` that is raised in one of your handlers (or while calling `get_updates` in the `Updater`) is forwarded to all registered error handlers, so you can react to them. You can register an error handler by calling `Dispatcher.add_error_handler(callback)`, where `callback` is a function that takes the arguments `bot, update, error`. `update` will be the update that caused the error and `error` the `TelegramError` that was raised.
Example: You're trying to send a message, but the user blocked the bot. An `Unauthorized` exception, a subclass of `TelegramError`, will be raised and delivered to your error handler, so you can delete it from your conversation list, if you keep one.
@ -34,23 +34,23 @@ dispatcher.add_error_handler(error_callback)
Here are some examples that would cause a `BadRequest` error to be raised:
```python
>>> bot.leaveChat(chat_id=<invalid chat id>)
>>> bot.leave_chat(chat_id=<invalid chat id>)
[...]
telegram.error.BadRequest: Chat not found
>>> bot.answerCallbackQuery(<invalid query id>)
>>> bot.answer_callback_query(<invalid query id>)
[...]
telegram.error.BadRequest: Query_id_invalid
>>> bot.getFile(<invalid file id>)
>>> bot.get_file(<invalid file id>)
[...]
telegram.error.BadRequest: Invalid file id
>>> bot.editMessageText(chat_id, "sample old message")
>>> bot.edit_message_text(chat_id, "sample old message")
[...]
telegram.error.BadRequest: Message is not modified
>>> bot.sendMessage(chat_id, 'a'*40960)
>>> bot.send_message(chat_id, 'a'*40960)
[...]
telegram.error.BadRequest: Message is too long
```