1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Edited TelegramAPIError class

This commit is contained in:
Steffo 2017-03-28 16:49:58 +02:00
parent 3e4160f692
commit 1c04743128

View file

@ -5,7 +5,11 @@ import datetime
class TelegramAPIError(Exception):
pass
def __init__(self, code, description):
# Error code
self.code = code
# Error description
self.description = description
class UpdateError(Exception):
@ -142,14 +146,8 @@ class Bot:
# Parse the json data as soon it's ready
data = await response.json()
# Check for errors in the request
if "description" in data:
error = data["description"]
if response.status != 200:
raise TelegramAPIError(f"Request returned {response.status} {response.reason}")
# Check for errors in the response
if not data["ok"]:
error = data["description"]
raise TelegramAPIError(f"Response returned an error: {error}")
if response.status != 200 or not data["ok"]:
raise TelegramAPIError(data["error_code"], data["description"])
# Return a dictionary containing the data
return data["result"]