Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`_
Expand Down
14 changes: 14 additions & 0 deletions telegram/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 10 additions & 3 deletions telegram/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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"""
Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this extra line is required for pep8 conformance. please bring it back.

raise ChatMigrated(migrate_to_chat_id)
if description:
return description

return data['result']

Expand Down