diff --git a/telethon/errors/__init__.py b/telethon/errors/__init__.py index e3106631..03125dc5 100644 --- a/telethon/errors/__init__.py +++ b/telethon/errors/__init__.py @@ -8,7 +8,7 @@ from threading import Thread from .common import ( ReadCancelledError, TypeNotFoundError, InvalidChecksumError, - BrokenAuthKeyError, SecurityError, CdnFileTamperedError, MultiError + InvalidBufferError, SecurityError, CdnFileTamperedError, MultiError ) # This imports the base errors too, as they're imported there diff --git a/telethon/errors/common.py b/telethon/errors/common.py index 9af19c9f..65cd363c 100644 --- a/telethon/errors/common.py +++ b/telethon/errors/common.py @@ -1,4 +1,6 @@ """Errors not related to the Telegram API itself""" +import struct + from ..tl import TLRequest @@ -39,14 +41,21 @@ class InvalidChecksumError(Exception): self.valid_checksum = valid_checksum -class BrokenAuthKeyError(Exception): +class InvalidBufferError(BufferError): """ - Occurs when the authorization key for a data center is not valid. + Occurs when the buffer is invalid, and may contain an HTTP error code. + For instance, 404 means "forgotten/broken authorization key", while """ - def __init__(self): - super().__init__( - 'The authorization key is broken, and it must be reset.' - ) + def __init__(self, payload): + self.payload = payload + if len(payload) == 4: + self.code = -struct.unpack('