mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-03 09:49:21 +01:00
parent
90913724ca
commit
f1ee54fa73
3 changed files with 25 additions and 3 deletions
|
@ -22,6 +22,7 @@ The following wonderful people contributed directly or indirectly to this projec
|
|||
- `njittam <https://github.com/njittam>`_
|
||||
- `Noam Meltzer <https://github.com/tsnoam>`_
|
||||
- `Oleg Shlyazhko <https://github.com/ollmer>`_
|
||||
- `overquota <https://github.com/overquota>`_
|
||||
- `Rahiel Kasim <https://github.com/rahiel>`_
|
||||
- `Shelomentsev D <https://github.com/shelomentsevd>`_
|
||||
- `sooyhwang <https://github.com/sooyhwang>`_
|
||||
|
|
|
@ -85,3 +85,17 @@ class TimedOut(NetworkError):
|
|||
|
||||
def __init__(self):
|
||||
super(TimedOut, self).__init__('Timed out')
|
||||
|
||||
|
||||
class ChatMigrated(TelegramError):
|
||||
|
||||
def __init__(self, new_chat_id):
|
||||
"""
|
||||
Args:
|
||||
new_chat_id (int):
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
super(ChatMigrated, self).__init__('Chat migrated')
|
||||
self.new_chat_id = new_chat_id
|
||||
|
|
|
@ -28,7 +28,7 @@ import urllib3
|
|||
from urllib3.connection import HTTPConnection
|
||||
|
||||
from telegram import (InputFile, TelegramError)
|
||||
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest
|
||||
from telegram.error import Unauthorized, NetworkError, TimedOut, BadRequest, ChatMigrated
|
||||
|
||||
_CON_POOL = None
|
||||
""":type: urllib3.PoolManager"""
|
||||
|
@ -135,8 +135,15 @@ def _parse(json_data):
|
|||
except ValueError:
|
||||
raise TelegramError('Invalid server response')
|
||||
|
||||
if not data.get('ok') and data.get('description'):
|
||||
return data['description']
|
||||
if not data.get('ok'):
|
||||
description = data.get('description')
|
||||
parameters = data.get('parameters')
|
||||
if parameters:
|
||||
migrate_to_chat_id = parameters.get('migrate_to_chat_id')
|
||||
if migrate_to_chat_id:
|
||||
raise ChatMigrated(migrate_to_chat_id)
|
||||
if description:
|
||||
return description
|
||||
|
||||
return data['result']
|
||||
|
||||
|
|
Loading…
Reference in a new issue