mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
New exception class for multiple errors (#965)
This commit is contained in:
@@ -8,7 +8,7 @@ from threading import Thread
|
||||
|
||||
from .common import (
|
||||
ReadCancelledError, TypeNotFoundError, InvalidChecksumError,
|
||||
BrokenAuthKeyError, SecurityError, CdnFileTamperedError
|
||||
BrokenAuthKeyError, SecurityError, CdnFileTamperedError, MultiError
|
||||
)
|
||||
|
||||
# This imports the base errors too, as they're imported there
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Errors not related to the Telegram API itself"""
|
||||
from ..tl import TLRequest
|
||||
|
||||
|
||||
class ReadCancelledError(Exception):
|
||||
@@ -67,3 +68,29 @@ class CdnFileTamperedError(SecurityError):
|
||||
super().__init__(
|
||||
'The CDN file has been altered and its download cancelled.'
|
||||
)
|
||||
|
||||
|
||||
class MultiError(Exception):
|
||||
"""Exception container for multiple `TLRequest`'s."""
|
||||
|
||||
def __new__(cls, exceptions, result, requests):
|
||||
if len(result) != len(exceptions) != len(requests):
|
||||
raise ValueError(
|
||||
'Need result, exception and request for each error')
|
||||
for e, req in zip(exceptions, requests):
|
||||
if not isinstance(e, BaseException):
|
||||
raise TypeError(
|
||||
'Expected and exception object, not %r' % e
|
||||
)
|
||||
if not isinstance(req, TLRequest):
|
||||
raise TypeError(
|
||||
'Expected TLRequest object, not %r' % req
|
||||
)
|
||||
|
||||
if len(exceptions) == 1:
|
||||
return exceptions[0]
|
||||
self = BaseException.__new__(cls)
|
||||
self.exceptions = list(exceptions)
|
||||
self.results = list(result)
|
||||
self.requests = list(requests)
|
||||
return self
|
||||
|
Reference in New Issue
Block a user