aiogram/aiogram/exceptions.py
2017-07-25 04:45:33 +03:00

30 lines
788 B
Python

from .utils import json
class ValidationError(Exception):
pass
class TelegramAPIError(Exception):
def __init__(self, message, method, status, body):
super(TelegramAPIError, self).__init__(
"A request to the Telegram API was unsuccessful.\n" + message)
self.method = method
self.status = status
self.body = body
def json(self):
if not self.body:
return None
try:
data = json.dumps(self.body)
except Exception:
data = None
return data
@property
def parameters(self):
from .types import ResponseParameters
data = self.json()
if data and 'parameters' in data:
return ResponseParameters.deserialize(data['parameters'])