Add more errors, change the way InvalidDC is created

This commit is contained in:
Lonami Exo 2017-05-20 15:25:07 +02:00
parent befc7a5657
commit fb9104417e
2 changed files with 21 additions and 8 deletions

View File

@ -28,13 +28,9 @@ class TypeNotFoundError(Exception):
class InvalidDCError(Exception): class InvalidDCError(Exception):
def __init__(self, new_dc): def __init__(self, rpc_error):
super().__init__( self.new_dc = rpc_error.__dict__.pop('additional_data')
self, 'Your phone number is registered to #{} DC. ' self.__dict__.update(rpc_error.__dict__)
'This should have been handled automatically; '
'if it has not, please restart the app.'.format(new_dc))
self.new_dc = new_dc
class InvalidChecksumError(Exception): class InvalidChecksumError(Exception):
@ -129,6 +125,23 @@ class RPCError(Exception):
'BOT_METHOD_INVALID': 'BOT_METHOD_INVALID':
'The API access for bot users is restricted. The method you tried ' 'The API access for bot users is restricted. The method you tried '
'to invoke cannot be executed as a bot.', 'to invoke cannot be executed as a bot.',
'PEER_ID_INVALID':
'An invalid Peer was used. Make sure to pass the right peer type.',
'MESSAGE_EMPTY': 'Empty or invalid UTF-8 message was sent.',
'MESSAGE_TOO_LONG':
'Message was too long. Current maximum length is 4096 UTF-8 characters.',
'USERNAME_INVALID':
'Unacceptable username. Must match r"[a-zA-Z][\w\d]{4,32}"',
'USERNAME_OCCUPIED': 'The username is already taken.',
'USERNAME_NOT_MODIFIED':
'The username is not different from the current username',
'USER_ID_INVALID':
'Invalid object ID for an user. Make sure to pass the right types.',
'CHAT_ID_INVALID':
'Invalid object ID for a chat. Make sure to pass the right types.',
'CHANNEL_INVALID':
'Invalid channel object. Make sure to pass the right types.',
'MESSAGE_ID_INVALID': 'The specified message ID is invalid.',
# 401 UNAUTHORIZED # 401 UNAUTHORIZED
'AUTH_KEY_UNREGISTERED': 'The key is not registered in the system.', 'AUTH_KEY_UNREGISTERED': 'The key is not registered in the system.',

View File

@ -363,7 +363,7 @@ class MtProtoSender:
sleep(error.additional_data) sleep(error.additional_data)
elif '_MIGRATE_' in error.message: elif '_MIGRATE_' in error.message:
raise InvalidDCError(error.additional_data) raise InvalidDCError(error)
else: else:
raise error raise error