Handle more key errors on forward message

This commit is contained in:
Lonami Exo 2019-05-17 12:18:31 +02:00
parent a71b095c1d
commit a4c2e45d6d
2 changed files with 19 additions and 13 deletions

View File

@ -142,18 +142,23 @@ class MessageParseMethods(UserMethods):
random_id = request if isinstance(request, int) else request.random_id random_id = request if isinstance(request, int) else request.random_id
if not utils.is_list_like(random_id): if not utils.is_list_like(random_id):
if random_id in random_to_id: msg = id_to_message.get(random_to_id.get(random_id))
return id_to_message[random_to_id[random_id]] if not msg:
else: self._log[__name__].warning(
return None 'Request %s had missing message mapping %s', request, result)
else:
# ``rnd in random_to_id`` is needed because trying to forward only return msg
# deleted messages causes `MESSAGE_ID_INVALID`, but forwarding
# valid and invalid messages in the same call makes the call try:
# succeed, although the API won't return those messages thus return [id_to_message[random_to_id[rnd]] for rnd in random_id]
# `random_to_id[rnd]` would `KeyError`. except KeyError:
return [id_to_message[random_to_id[rnd]] # Sometimes forwards fail (`MESSAGE_ID_INVALID` if a message gets
if rnd in random_to_id else None # deleted or `WORKER_BUSY_TOO_LONG_RETRY` if there are issues at
for rnd in random_id] # Telegram), in which case we get some "missing" message mappings.
# Log them with the hope that we can better work around them.
self._log[__name__].warning(
'Request %s had missing message mappings %s', request, result)
return [id_to_message.get(random_to_id.get(rnd)) for rnd in random_to_id]
# endregion # endregion

View File

@ -270,4 +270,5 @@ WALLPAPER_INVALID,400,The input wallpaper was not valid
WC_CONVERT_URL_INVALID,400,WC convert URL invalid WC_CONVERT_URL_INVALID,400,WC convert URL invalid
WEBPAGE_CURL_FAILED,400,Failure while fetching the webpage with cURL WEBPAGE_CURL_FAILED,400,Failure while fetching the webpage with cURL
WEBPAGE_MEDIA_EMPTY,400,Webpage media empty WEBPAGE_MEDIA_EMPTY,400,Webpage media empty
WORKER_BUSY_TOO_LONG_RETRY,500,Telegram workers are too busy to respond immediately
YOU_BLOCKED_USER,400,You blocked this user YOU_BLOCKED_USER,400,You blocked this user

1 name codes description
270 WC_CONVERT_URL_INVALID 400 WC convert URL invalid
271 WEBPAGE_CURL_FAILED 400 Failure while fetching the webpage with cURL
272 WEBPAGE_MEDIA_EMPTY 400 Webpage media empty
273 WORKER_BUSY_TOO_LONG_RETRY 500 Telegram workers are too busy to respond immediately
274 YOU_BLOCKED_USER 400 You blocked this user