mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 12:59:46 +00:00
Properly handle bot timeouts when clicking buttons
This commit is contained in:
@@ -66,23 +66,5 @@ def rpc_message_to_error(rpc_error, report_method=None):
|
||||
capture = int(m.group(1)) if m.groups() else None
|
||||
return cls(capture=capture)
|
||||
|
||||
if rpc_error.error_code == 400:
|
||||
return BadRequestError(rpc_error.error_message)
|
||||
|
||||
if rpc_error.error_code == 401:
|
||||
return UnauthorizedError(rpc_error.error_message)
|
||||
|
||||
if rpc_error.error_code == 403:
|
||||
return ForbiddenError(rpc_error.error_message)
|
||||
|
||||
if rpc_error.error_code == 404:
|
||||
return NotFoundError(rpc_error.error_message)
|
||||
|
||||
if rpc_error.error_code == 406:
|
||||
return AuthKeyError(rpc_error.error_message)
|
||||
|
||||
if rpc_error.error_code == 500:
|
||||
return ServerError(rpc_error.error_message)
|
||||
|
||||
return RPCError('{} (code {})'.format(
|
||||
rpc_error.error_message, rpc_error.error_code))
|
||||
cls = base_errors.get(rpc_error.error_code, RPCError)
|
||||
return cls(rpc_error.error_message)
|
||||
|
@@ -97,6 +97,19 @@ class ServerError(RPCError):
|
||||
self.message = message
|
||||
|
||||
|
||||
class BotTimeout(RPCError):
|
||||
"""
|
||||
Clicking the inline buttons of bots that never (or take to long to)
|
||||
call ``answerCallbackQuery`` will result in this "special" RPCError.
|
||||
"""
|
||||
code = -503
|
||||
message = 'Timeout'
|
||||
|
||||
def __init__(self, message):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
|
||||
|
||||
class BadMessageError(Exception):
|
||||
"""Occurs when handling a bad_message_notification."""
|
||||
ErrorMessages = {
|
||||
@@ -142,3 +155,9 @@ class BadMessageError(Exception):
|
||||
'Unknown error code (this should not happen): {}.'.format(code)))
|
||||
|
||||
self.code = code
|
||||
|
||||
|
||||
base_errors = {x.code: x for x in (
|
||||
InvalidDCError, BadRequestError, UnauthorizedError, ForbiddenError,
|
||||
NotFoundError, AuthKeyError, FloodError, ServerError, BotTimeout
|
||||
)}
|
||||
|
Reference in New Issue
Block a user